libUTL++
TSortedCollection.h
1 #pragma once
2 
4 
5 #include <libutl/SortedCollection.h>
6 #include <libutl/TCollection.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
26 
28 template <class T = Object>
29 class TSortedCollection : public TCollection<T>
30 {
32 
33 public:
35  : TCollection<T>(col)
36  {
37  }
38 
39  void
40  clobber(const SortedCollection* rhs)
41  {
42  col()->clobber(rhs);
43  }
44 
45  void
46  reverse()
47  {
48  col()->reverse();
49  }
50 
51  void
52  findEqualRange(const Object& key, BidIt& first, BidIt& last) const
53  {
54  col()->findEqualRange(key, first, last);
55  }
56 
57  void
58  findEqualRange(const Object& key, BidIt& first, BidIt& last)
59  {
60  col()->findEqualRange(key, first, last);
61  }
62 
63  void
64  findFirstIt(const Object& key, BidIt& it, bool insert = false) const
65  {
66  col()->findFirstIt(key, it, insert);
67  }
68 
69  virtual void
70  findFirstIt(const Object& key, BidIt& it, bool insert = false)
71  {
72  col()->findFirstIt(key, it, insert);
73  }
74 
75  void
76  findLastIt(const Object& key, BidIt& it) const
77  {
78  col()->findLastIt(key, it);
79  }
80 
81  virtual void
82  findLastIt(const Object& key, BidIt& it)
83  {
84  col()->findLastIt(key, it);
85  }
86 
87  T*
88  findLinear(const Object& key) const
89  {
90  return (T*)(col()->findLinear(key));
91  }
92 
93  T*
94  findLinearSorted(const Object& key) const
95  {
96  return (T*)(col()->findLinearSorted(key));
97  }
98 
99  TSortedCollection<T>& operator+=(const SortedCollection& rhs)
100  {
101  col()->operator+=(rhs);
102  }
103 
104  TSortedCollection<T>& operator-=(const SortedCollection& rhs)
105  {
106  col()->operator-=(rhs);
107  return self;
108  }
109 
110  Collection*
111  difference(const SortedCollection* rhs, Collection* out = nullptr) const
112  {
113  return col()->difference(rhs, out);
114  }
115 
116  void
117  intersect(const SortedCollection* rhs)
118  {
119  col()->intersect(rhs);
120  }
121 
122  Collection*
123  intersection(const SortedCollection* rhs,
124  Collection* out = nullptr,
125  bool multiSet = false) const
126  {
127  return col()->intersection(rhs, out, multiSet);
128  }
129 
130  size_t
131  intersectCard(const SortedCollection* rhs) const
132  {
133  return col()->intersectCard(rhs);
134  }
135 
136  bool
137  intersects(const SortedCollection* rhs) const
138  {
139  return col()->intersects(rhs);
140  }
141 
142  bool
143  isSubSet(const SortedCollection* rhs) const
144  {
145  return col()->isSubSet(rhs);
146  }
147 
148  bool
149  isSuperSet(const SortedCollection* rhs) const
150  {
151  return col()->isSuperSet(rhs);
152  }
153 
154  Collection*
155  merge(const SortedCollection* rhs, Collection* out = nullptr) const
156  {
157  return col()->merge(rhs, out);
158  }
159 
160  Collection*
161  symmetricDifference(const SortedCollection* rhs, Collection* out = nullptr) const
162  {
163  return col()->symmetricDifference(rhs, out);
164  }
165 
166  void
167  symmetricDifference(const SortedCollection* rhs, Collection* lhsOut, Collection* rhsOut) const
168  {
169  col()->symmetricDifference(rhs, lhsOut, rhsOut);
170  }
171 
172  Collection*
173  unique(Collection* out = nullptr)
174  {
175  return col()->unique(out);
176  }
177 
178  TSortedCollection<T>& operator&=(const SortedCollection* rhs)
179  {
180  col()->operator&=(rhs);
181  return self;
182  }
183 
184  bool operator<=(const SortedCollection* rhs)
185  {
186  return col()->operator<=(rhs);
187  }
188 
189  bool operator>=(const SortedCollection* rhs)
190  {
191  return col()->operator>=(rhs);
192  }
193 
194  void
195  multiKeyQuickSort(bool key = true, bool reverse = false)
196  {
197  col()->multiKeyQuickSort(key, reverse);
198  }
199 
200  void
201  sort()
202  {
203  col()->sort();
204  }
205 
206  void
207  sort(uint_t algorithm)
208  {
209  col()->sort(algorithm);
210  }
211 
212  operator SortedCollection&()
213  {
214  return *col();
215  }
216 
217  operator const SortedCollection&() const
218  {
219  return *col();
220  }
221 
222  operator SortedCollection*()
223  {
224  return col();
225  }
226 
227  operator const SortedCollection*() const
228  {
229  return col();
230  }
231 
232 protected:
233  const SortedCollection*
234  col() const
235  {
236  ASSERTD(_col != nullptr);
237  return utl::cast<SortedCollection>(_col);
238  }
239 
241  col()
242  {
243  ASSERTD(_col != nullptr);
244  return utl::cast<SortedCollection>(_col);
245  }
246 };
247 
249 
250 UTL_NS_END;
251 
253 
bool isSubSet(const SortedCollection *rhs) const
Determine whether self is a subset of rhs.
Templated proxy for SortedCollection.
#define UTL_CLASS_IMPL_TPL(className, T)
Implementation of standard UTL++ functionality for a template class.
Definition: macros.h:906
Collection * difference(const SortedCollection *rhs, Collection *out=nullptr) const
Determine the difference between self and rhs.
void intersect(const SortedCollection *rhs)
Set self to the intersection of self and rhs.
void intersect(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, FwdIt &out, const Ordering *ordering=nullptr, bool cloning=false, bool multiSet=false, bool outIsLHS=false)
Determine the intersection of two sorted sequences.
void merge(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, FwdIt &out, const Ordering *ordering=nullptr, bool cloning=false)
Merge two sorted sequences into a single sorted sequence.
bool intersects(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, const Ordering *ordering=nullptr)
Determine whether the intersection of two sorted sequences is non-empty.
void difference(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, FwdIt &out, const Ordering *ordering=nullptr, bool cloning=false, bool outIsLHS=false)
Determine the difference between two sorted sequences.
void sort(const FwdIt &begin, const FwdIt &end, const Ordering *ordering=nullptr, uint_t algorithm=sort_quickSort, size_t size=size_t_max)
Sort a sequence using a given algorithm.
Collection * intersection(const SortedCollection *rhs, Collection *out=nullptr, bool multiSet=false) const
Determine the intersection of self and rhs.
void multiKeyQuickSort(const FwdIt &begin, const FwdIt &end, bool key=true, bool reverse=false, size_t size=size_t_max)
Multi-key quick-sort a sequence.
void clobber(const SortedCollection *rhs)
Where self and rhs intersect, make self&#39;s object equal to the rhs version (i.e.
void findLastIt(const Object &key, BidIt &it) const
Find the last object matching the given key.
void reverse(const BidIt &begin, const BidIt &end)
Reverse a sequence.
Object * findLinear(const Object &key) const
Linear search for an object matching the given key.
void symmetricDifference(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, FwdIt &out, const Ordering *ordering=nullptr, bool cloning=false)
Determine the symmetric difference of two sorted sequences.
void findFirstIt(const Object &key, BidIt &it, bool insert=false) const
Find the first object matching the given key.
void sort()
Sort the collection using the quicksort algorithm.
Abstraction for a Collection whose objects may be sorted.
size_t intersectCard(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, const Ordering *ordering=nullptr, bool multiSet=false)
Determine the cardinality of the intersection of two sorted sequences.
void multiKeyQuickSort(bool key=true, bool reverse=false)
Multi-key quick-sort the collection.
Templated proxy for Collection.
Definition: TCollection.h:29
bool intersects(const SortedCollection *rhs) const
Determine whether the intersection of self and rhs is non-empty.
bool isSuperSet(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, const Ordering *ordering=nullptr)
Determine whether the lhs sorted sequence is a superset of the rhs sorted sequence.
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Collection * unique(Collection *out=nullptr)
Remove duplicate objects.
Bi-directional iterator abstraction.
Definition: BidIt.h:25
Collection * merge(const SortedCollection *rhs, Collection *out=nullptr) const
Merge with rhs to form a single sorted sequence.
#define UTL_CLASS_DECL_TPL(DC, T, BC)
Declaration of standard UTL++ functionality for a template class with one parameter.
Definition: macros.h:713
Object * findLinearSorted(const Object &key) const
Linear search for an object matching the given key.
void findEqualRange(const Object &key, BidIt &begin, BidIt &end) const
Find the range elements [begin,end) that match a given key.
bool isSubSet(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, const Ordering *ordering=nullptr)
Determine whether the lhs sorted sequence is a subset of the rhs sorted sequence. ...
size_t intersectCard(const SortedCollection *rhs) const
Determine the cardinality of the intersection of self and rhs.
Collection * symmetricDifference(const SortedCollection *rhs, Collection *out=nullptr) const
Determine the symmetric difference of self and rhs.
void clobber()
Fake read/write access to all memory.
Definition: util_inl.h:973
Root of UTL++ class hierarchy.
Definition: Object.h:52
bool isSuperSet(const SortedCollection *rhs) const
Determine whether self is a superset of rhs.
void unique(const FwdIt &begin, const FwdIt &end, FwdIt &out, const Ordering *ordering=nullptr, bool cloning=false, bool outIsSrc=false)
Remove duplicate objects from a sorted sequence.
#define ASSERTD
Do an assertion in DEBUG mode only.
A collection of objects.
Definition: Collection.h:62
void reverse()
Reverse the order of the contained objects.