45# ifndef TPL_DYNMAPTREE_H
46# define TPL_DYNMAPTREE_H
48# include <type_traits>
83 typename Key,
typename Data,
89 Dft_Pair_Cmp<Key, Data, Compare>>
91 using Pair = std::pair<Key, Data>;
102 keys.for_each([
this] (
auto &
k) { this->
insert(std::make_pair(
k, Data())); });
121 static const Data &
get_data(
const Key & key)
noexcept
126 static const Key &
get_key(Data * data_ptr)
noexcept
131 static const Key &
get_key(
const Data * data_ptr)
noexcept
164 std::forward<Data>(data)));
185 std::forward<Data>(data)));
192 Pair *
put(
const Key & key,
const Data & data)
199 return insert(key, std::forward<Data>(data));
204 return insert(std::forward<Key>(key), data);
209 return insert(std::forward<Key>(key), std::forward<Data>(data));
222 static_assert(std::is_default_constructible_v<Data>,
223 "DynMapTree::remove() requires Data to be default-constructible");
225 return this->
del(p).second;
230 static_assert(std::is_default_constructible_v<Data>,
231 "DynMapTree::remove() requires Data to be default-constructible");
232 Pair p(std::forward<Key>(key), Data());
233 return this->
del(p).second;
238 static_assert(std::is_default_constructible_v<Data>,
239 "DynMapTree::remove_key() requires Data to be default-constructible");
255 static_assert(std::is_default_constructible_v<Data>,
256 "DynMapTree::search() requires Data to be default-constructible");
262 static_assert(std::is_default_constructible_v<Data>,
263 "DynMapTree::search() requires Data to be default-constructible");
267 bool has(
const Key & key)
const noexcept {
return search(key) !=
nullptr; }
269 bool has(Key && key)
const noexcept {
return search(std::move(key)) !=
nullptr; }
271 bool contains(
const Key & key)
const noexcept {
return has(key); }
273 bool contains(Key && key)
const noexcept {
return has(std::move(key)); }
283 static_assert(std::is_default_constructible_v<Data>,
284 "DynMapTree::find() requires Data to be default-constructible");
288 const Data &
find(
const Key & key)
const
290 static_assert(std::is_default_constructible_v<Data>,
291 "DynMapTree::find() requires Data to be default-constructible");
297 static_assert(std::is_default_constructible_v<Data>,
298 "DynMapTree::operator[] requires Data to be default-constructible");
304 return this->
find(key);
309 static_assert(std::is_default_constructible_v<Data>,
310 "DynMapTree::operator[] requires Data to be default-constructible");
316 return this->
find(std::move(key));
323 return this->
template maps<Key>([] (
auto p) {
return p.first; });
332 return this->
template maps<Data>([] (
auto p) {
return p.second; });
342 for (
Iterator it(*
this); it.has_curr(); it.next_ne())
354 for (
Iterator it(*
this); it.has_curr(); it.next_ne())
375 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
382 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
388 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
396 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
404 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
416 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
424 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
428 template <
typename T,
class Op,
class C>
432 for (
auto it = c.get_it(); it.has_curr(); it.next_ne())
434 const auto & curr = it.get_curr();
C++20 concepts for constraining comparison functors.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
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.
QuadTree - Hierarchical spatial index for 2D points.
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
@ Tree
Basic arc (in spanning tree).
DynMapTree< typename C::Item_Type, T > map_unify(const C &c, Op op)
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.