Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Partition.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Traversal_Partition_h_
5#define _Stroika_Foundation_Traversal_Partition_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "Stroika/Foundation/Math/Common.h"
11
12/**
13 * \file
14 *
15 * STATUS: PRELIMINARY DRAFT.
16 *
17 * TODO:
18 * @todo Implementation NOT correct. Cases reported as partition true are true,
19 * but case of DiscreteRange<int> {1, 2}, DiscreteRange<int> {3, 4}) not handled right - where
20 * elts arent equal, but both sides closed and next elt is next point.
21 * (retest/revisit as of Stroika 2.1b8 --- maybe fixed)
22 *
23 * @todo Should be optional param to produce the Range that the elements form a partion of.
24 *
25 * @todo Consider if/how this integrates with std::partition
26 *
27 * @todo Consider if/how this intergrates with DisjointRange
28 *
29 * @todo Support ANY STL container (like initializer_list) as argument. So just anytthing you can say begin/end on to get
30 * iterator.
31 *
32 */
33
34namespace Stroika::Foundation::Traversal {
35
36 /**
37 * Checks if the given collection of ranges 'cover' an interval, with no overlap (sharing no points).
38 *
39 * \note Half open (Range) intervals are generally best candidates for creating partitions
40 *
41 * \pre the Range elements RANGE_TYPE - must be natively sortable (note we do not require that they be given in order)
42 *
43 * \par Example Usage
44 * \code
45 * using RT = Range<double>;
46 * EXPECT_TRUE (not IsPartition (Sequence<RT>{RT{1, 2}, RT{3, 4}}));
47 * EXPECT_TRUE (IsPartition (Sequence<RT>{RT{1, 2}, RT{2, 4}}));
48 * \endcode
49 *
50 * \par Example Usage (using integers)
51 * \code
52 * using RT = Range<int, Explicit<int, ExplicitOpenness<Openness::eClosed, Openness::eOpen>>>; // half open intervals best for partitions
53 * EXPECT_TRUE (not IsPartition (Sequence<RT>{RT{1, 2}, RT{3, 4}}));
54 * EXPECT_TRUE (IsPartition (Sequence<RT>{RT{1, 2}, RT{2, 4}}));
55 * \endcode
56 */
57 template <Traversal::IRange RANGETYPE>
58 bool IsPartition (const Iterable<RANGETYPE>& iterable);
59 template <Traversal::IRange RANGETYPE, typename /*predicate<typename RANGETYPE::value_type>*/ RANGE_ELT_COMPARER>
60 bool IsPartition (const Iterable<RANGETYPE>& iterable, RANGE_ELT_COMPARER comparer);
61
62}
63
64/*
65 ********************************************************************************
66 ******************************* Implementation Details *************************
67 ********************************************************************************
68 */
69#include "Partition.inl"
70
71#endif /*_Stroika_Foundation_Traversal_Partition_h_ */
bool IsPartition(const Iterable< RANGETYPE > &iterable)
Definition Partition.inl:47