35 template <
typename Key,
class Cmp = std::less<Key>>
54 return cmp(a, b) or
cmp(b, a);
58 template <
typename Key,
class Cmp = std::less<Key>>
81 template <
typename Key,
class Cmp>
99 : array(a), cmp(c), not_equal_key(cmp), equal_key(cmp)
111 lint_t pos = search(item, 0, array.
size() - 1);
113 if (pos == array.
size())
114 return &array.
append(item);
116 if (equal_key(item, array.
at(pos)))
119 return &array.
insert(pos, item);
124 lint_t pos = search(item, 0, array.
size() - 1);
126 if (pos == array.
size())
127 return &array.
append(std::forward<Key>(item));
129 if (equal_key(item, array.
at(pos)))
132 return &array.
insert(pos, std::forward<Key>(item));
137 lint_t pos = search(item, 0, array.
size() - 1);
139 if (pos == array.
size())
140 return &array.
append(item);
142 return &array.
insert(pos, item);
147 lint_t pos = search(item, 0, array.
size() - 1);
149 if (pos == array.
size())
150 return &array.
append(std::forward<Key>(item));
152 return &array.
insert(pos, std::forward<Key>(item));
157 lint_t pos = search(item, 0, array.
size() - 1);
159 if (pos == array.
size())
160 return &array.
append(item);
162 if (equal_key(item, array.
at(pos)))
165 return &array.
insert(pos, item);
170 lint_t pos = search(item, 0, array.
size() - 1);
172 if (pos == array.
size())
173 return &array.
append(std::forward<Key>(item));
175 if (equal_key(item, array.
at(pos)))
178 return &array.
insert(pos, std::forward<Key>(item));
193 return search(item, 0, array.
size() - 1);
197 template <
typename Key,
class Cmp>
215 : array(a), cmp(c), not_equal_key(cmp), equal_key(cmp)
222 return array.template is_sorted<Cmp>(
cmp);
229 if (pos < array.
size())
232 return &array.
append(item);
239 if (pos < array.
size())
242 return &array.
append(std::forward<Key>(item));
247 return &array.
append(item);
252 return &array.
append(std::forward<Key>(item));
259 if (pos < array.
size())
262 return &array.
append(item);
269 if (pos < array.
size())
272 return &array.
append(std::forward<Key>(item));
289 return search(item, 0, array.
size() - 1);
293 template <
typename Key,
class Cmp,
class ArraySetOp>
311 : ArraySetOp(array, _cmp), array(cap), cmp(_cmp)
317 : ArraySetOp(array, _cmp), array(), cmp(_cmp)
329 : ArraySetOp(array, a.cmp), array(a.array), cmp(a.cmp)
362 std::swap(cmp, a.
cmp);
392 return ArraySetOp::insert(k);
397 return ArraySetOp::insert(std::forward<Key>(k));
402 return ArraySetOp::insert_dup(k);
407 return ArraySetOp::insert_dup(std::forward<Key>(k));
412 lint_t pos = ArraySetOp::search(item, 0,
lint_t(this->size()) - 1);
414 if (pos >= this->size() or ArraySetOp::not_equal_key(item, array.
at(pos)))
417 return &array.
at(pos);
420 const Key *
search(
const Key & item)
const 422 lint_t pos = ArraySetOp::search(item, 0,
lint_t(this->size()) - 1);
424 if (pos >= this->size() or ArraySetOp::not_equal_key(item, array.
at(pos)))
427 return &array.
at(pos);
432 Key * result = search(item);
433 if (result ==
nullptr)
434 throw std::domain_error(
"Item does not exist");
438 const Key &
find(
const Key & item)
const 440 const Key * result = search(item);
441 if (result ==
nullptr)
442 throw std::domain_error(
"Item does not exist");
446 bool remove(
const Key & item)
448 lint_t pos = ArraySetOp::search(item, 0,
lint_t(this->size()) - 1);
450 if (pos >= this->size() or ArraySetOp::not_equal_key(array.
at(pos), item))
453 ArraySetOp::remove_pos(pos);
462 const Key & operator [] (
nat_t i)
const 505 return Iterator(*
this);
510 return Iterator(*
this);
515 return Iterator(*
this, size());
520 return Iterator(*
this, size());
524 template <
typename Key,
class Cmp,
class ArraySetOp>
529 for (
const Key & item : l)
533 template <
typename Key,
class Cmp = std::less<Key>>
535 UnsortedArraySetOp<Key, Cmp>>
541 template <
typename Key,
class Cmp = std::less<Key>>
543 public GenArraySet<Key, Cmp, SortedArraySetOp<Key, Cmp>>
549 template <
typename Key,
class Cmp = std::less<Key>,
553 using Base = ArrayType<Key, Cmp>;
560 template <
typename Key,
class Cmp = std::less<Key>,
561 template <
typename,
class>
class TreeType =
RankedTreap>
564 using Base = TreeType<Key, Cmp>;
571 template <
typename Key,
class Cmp = std::equal_to<Key>,
572 template <
typename,
class>
class HashTableType =
LHashTable>
573 class HashSet :
public HashTableType<Key, Cmp>
575 using Base = HashTableType<Key, Cmp>;
Cmp & cmp
Definition: set.H:61
Key DataType
Definition: set.H:302
void quicksort(ArrayType &, lint_t, lint_t, Cmp &)
Definition: sort.H:253
Key * append(Key &&k)
Definition: set.H:395
Key & find(const Key &item)
Definition: set.H:430
T remove_pos_closing_breach(nat_t pos)
Definition: array.H:596
Key ItemType
Definition: set.H:300
nat_t position(const Key &item)
Definition: set.H:286
Cmp & cmp
Definition: set.H:307
Iterator begin()
Definition: set.H:503
EqualKey< Key, Cmp > equal_key
Definition: set.H:205
Iterator begin() const
Definition: set.H:508
Key * insert(const Key &item)
Definition: set.H:225
GenArraySet(GenArraySet &&a)
Definition: set.H:334
Key * insert_dup(const Key &item)
Definition: set.H:245
Definition: setalgorithms.H:36
Key remove_pos(nat_t pos)
Definition: set.H:275
Iterator(const GenArraySet &a)
Definition: set.H:478
nat_t size() const
Definition: set.H:380
SortedArraySetOp(DynArray< Key > &a, Cmp &c)
Definition: set.H:98
NotEqualKey(Cmp &&c=Cmp())
Definition: set.H:46
EqualKey< Key, Cmp > equal_key
Definition: set.H:90
NotEqualKey(Cmp &c)
Definition: set.H:40
lint_t sequential_search(const ArrayType< T > &, const T &, lint_t, lint_t, Cmp &)
Definition: sort.H:125
Cmp & cmp
Definition: set.H:38
Iterator(Iterator &&itor)
Definition: set.H:496
T & insert(nat_t pos, const T &item)
Definition: array.H:520
nat_t size() const
Definition: array.H:467
DynArray< Key > array
Definition: set.H:306
Key * search_or_insert(Key &&item)
Definition: set.H:168
Cmp & get_cmp()
Definition: set.H:365
lint_t search(const Key &k, lint_t l, lint_t r) const
Definition: set.H:92
TreeType< MapKey< Key, Value >, CmpWrapper< Key, Value, Cmp > > ContainerType
Definition: set.H:568
T & at(nat_t i)
Definition: array.H:653
T & append(const T &item)
Definition: array.H:562
const Cmp & get_cmp() const
Definition: set.H:370
T remove_pos(nat_t pos)
Definition: array.H:576
Key * insert_dup(Key &&item)
Definition: set.H:145
void clear()
Definition: array.H:477
bool operator()(const Key &a, const Key &b) const
Definition: set.H:52
HashTableType< MapKey< Key, Value >, CmpWrapper< Key, Value, Cmp > > ContainerType
Definition: set.H:579
void swap(GenArraySet &a)
Definition: set.H:359
void swap(DynArray &a)
Definition: array.H:456
Key * append(const Key &k)
Definition: set.H:390
const Key * search(const Key &item) const
Definition: set.H:420
Key * insert_dup(Key &&item)
Definition: set.H:250
long long lint_t
Definition: types.H:49
const Key & select(nat_t i)
Definition: set.H:280
bool is_sorted() const
Definition: set.H:220
Key * search_or_insert(const Key &item)
Definition: set.H:155
Key * append_dup(Key &&k)
Definition: set.H:405
bool is_sorted() const
Definition: set.H:104
Definition: containeralgorithms.H:33
Key KeyType
Definition: set.H:301
Key remove_pos(nat_t pos)
Definition: set.H:181
bool is_empty() const
Definition: array.H:472
GenArraySet(Cmp &&_cmp=Cmp())
Definition: set.H:316
Key * search_or_insert(const Key &item)
Definition: set.H:255
Iterator(const Iterator &itor)
Definition: set.H:490
nat_t SizeType
Definition: set.H:304
Iterator end()
Definition: set.H:513
Key ValueType
Definition: set.H:303
Key * insert(Key &&item)
Definition: set.H:122
Key * insert(const Key &item)
Definition: set.H:109
const Key & find(const Key &item) const
Definition: set.H:438
Key * insert_dup(const Key &item)
Definition: set.H:135
Key * search_or_insert(Key &&item)
Definition: set.H:265
EqualKey(Cmp &c)
Definition: set.H:63
Iterator(const GenArraySet &a, nat_t c)
Definition: set.H:484
NotEqualKey< Key, Cmp > not_equal_key
Definition: set.H:204
EqualKey(Cmp &&c=Cmp())
Definition: set.H:69
Iterator()
Definition: set.H:472
unsigned long int nat_t
Definition: types.H:50
UnsortedArraySetOp(DynArray< Key > &a, Cmp &c)
Definition: set.H:214
NotEqualKey< Key, Cmp > not_equal_key
Definition: set.H:89
GenArraySet(nat_t cap, Cmp &&_cmp=Cmp())
Definition: set.H:322
GenArraySet(const GenArraySet &a)
Definition: set.H:328
Key * append_dup(const Key &k)
Definition: set.H:400
nat_t position(const Key &item)
Definition: set.H:191
const Key & select(nat_t i)
Definition: set.H:186
lint_t search(const Key &k, lint_t l, lint_t r) const
Definition: set.H:208
void clear()
Definition: set.H:385
ArrayType< MapKey< Key, Value >, CmpWrapper< Key, Value, Cmp > > ContainerType
Definition: set.H:557
lint_t binary_search(const ArrayType< T > &, const T &, lint_t, lint_t, Cmp &)
Definition: sort.H:81
Iterator end() const
Definition: set.H:518
GenArraySet(nat_t cap, Cmp &_cmp)
Definition: set.H:310
Key * search(const Key &item)
Definition: set.H:410
bool is_empty() const
Definition: set.H:375
Key * insert(Key &&item)
Definition: set.H:235