45# ifndef TPL_DYNMAPTREE_H
46# define TPL_DYNMAPTREE_H
48# include <type_traits>
82 typename Key,
typename Data,
87 Dft_Pair_Cmp<Key, Data, Compare>>
89 using Pair = std::pair<Key, Data>;
100 keys.for_each([
this] (
auto &
k) { this->
insert(std::make_pair(
k,
Data())); });
162 std::forward<Data>(data)));
183 std::forward<Data>(data)));
197 return insert(key, std::forward<Data>(data));
202 return insert(std::forward<Key>(key), data);
207 return insert(std::forward<Key>(key), std::forward<Data>(data));
220 static_assert(std::is_default_constructible_v<Data>,
221 "DynMapTree::remove() requires Data to be default-constructible");
223 return this->
del(p).second;
228 static_assert(std::is_default_constructible_v<Data>,
229 "DynMapTree::remove() requires Data to be default-constructible");
230 Pair p(std::forward<Key>(key),
Data());
231 return this->
del(p).second;
236 static_assert(std::is_default_constructible_v<Data>,
237 "DynMapTree::remove_key() requires Data to be default-constructible");
253 static_assert(std::is_default_constructible_v<Data>,
254 "DynMapTree::search() requires Data to be default-constructible");
260 static_assert(std::is_default_constructible_v<Data>,
261 "DynMapTree::search() requires Data to be default-constructible");
265 bool has(
const Key & key)
const noexcept {
return search(key) !=
nullptr; }
267 bool has(Key && key)
const noexcept {
return search(std::move(key)) !=
nullptr; }
269 bool contains(
const Key & key)
const noexcept {
return has(key); }
271 bool contains(Key && key)
const noexcept {
return has(std::move(key)); }
281 static_assert(std::is_default_constructible_v<Data>,
282 "DynMapTree::find() requires Data to be default-constructible");
288 static_assert(std::is_default_constructible_v<Data>,
289 "DynMapTree::find() requires Data to be default-constructible");
295 static_assert(std::is_default_constructible_v<Data>,
296 "DynMapTree::operator[] requires Data to be default-constructible");
302 return this->
find(key);
307 static_assert(std::is_default_constructible_v<Data>,
308 "DynMapTree::operator[] requires Data to be default-constructible");
314 return this->
find(std::move(key));
321 return this->
template maps<Key>([] (
auto p) {
return p.first; });
330 return this->
template maps<Data>([] (
auto p) {
return p.second; });
340 for (
Iterator it(*
this); it.has_curr(); it.next_ne())
352 for (
Iterator it(*
this); it.has_curr(); it.next_ne())
373 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
380 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
386 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
394 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
402 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
414 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
422 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
426 template <
typename T,
class Op,
class C>
430 for (
auto it = c.get_it(); it.has_curr(); it.next_ne())
432 const auto & curr = it.get_curr();
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
Dynamic map implemented with an AVL tree.
Dynamic map implemented with a classic binary search tree.
Dynamic map implemented with a randomized BST.
Dynamic map implemented with a red-black tree.
Dynamic map implemented with a splay tree.
Dynamic map implemented with a ranked treap.
Dynamic map implemented with a treap.
Generic key-value map implemented on top of a binary search tree.
Pair * put(Key &&key, Data &&data)
bool has(Key &&key) const noexcept
bool contains(Key &&key) const noexcept
static const Key & get_key(Data *data_ptr) noexcept
void remove_key(const Key &key)
Pair * insert(Key &&key, const Data &data)
typename Base::Iterator Iterator
DynMapTree(const DynList< Key > &keys)
Data remove(const Key &key)
Deletes the pair key,data
const Data & find(const Key &key) const
Pair * search(Key &&key) const noexcept
Pair * append(Key &&key, const Data &data)
Pair * put(const Key &key, const Data &data)
Alias for insert().
Pair * put(const Key &key, Data &&data)
Pair * append(const Key &key, const Data &data)
DynList< Pair * > items_ptr()
Collect pointers to all stored pairs.
Pair * append(const Key &key, Data &&data=Data())
Pair * search(const Key &key) const noexcept
Collect all keys.
bool has(const Key &key) const noexcept
static const Key & get_key(const Data *data_ptr) noexcept
DynList< Key > keys() const
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
Pair * put(Key &&key, const Data &data)
bool contains(const Key &key) const noexcept
Data & operator[](const Key &key)
std::pair< Key, Data > Pair
Pair * append(Key &&key, Data &&data=Data())
static Data & get_data(Key &key) noexcept
Pair * insert(const Key &key, Data &&data=Data())
DynList< Data > values() const
Collect all values.
Pair * insert(Key &&key, Data &&data=Data())
DynList< Data * > values_ptr()
Collect pointers to all values.
static const Data & get_data(const Key &key) noexcept
Data & find(const Key &key)
Find the value associated with key.
Dynamic set backed by balanced binary search trees with automatic memory management.
Key del(const Key &key)
Deletes key and returns a full copy of stored key.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
Key & find(const Key &key) const
Returns a modifiable reference to an element within the set.
Key * search(const Key &key) const
Find an element in the set.
Key * search_or_insert(const Key &key)
Look for the key in the binary search tree or inserts it if it is not found.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Main namespace for Aleph-w library functions.
@ Tree
Basic arc (in spanning tree).
DynMapTree< typename C::Item_Type, T > map_unify(const C &c, Op op)
DynList< T > maps(const C &c, Op op)
Classic map operation.
AVL binary search tree with nodes without virtual destructor.
Default comparator for pair types in hash maps.
AVL tree implementation (height-balanced BST).
Generic unbalanced binary search tree.
Dynamic set implementations based on balanced binary search trees.
Randomized binary search tree.
Red-Black tree implementation (bottom-up balancing).
Top-down splay tree implementation (without rank support).
Treap with rank (order statistics).
Treap: randomized BST combining tree and heap properties.