27 # ifndef TPL_DYNMAPTREE_H 28 # define TPL_DYNMAPTREE_H 30 # include <tpl_dynSetTree.H> 32 using namespace Aleph;
59 typename Key,
typename Data,
60 template <
typename,
class>
class Tree = Avl_Tree,
61 class Compare = Aleph::less<Key>>
64 Dft_Pair_Cmp<Key, Data, Compare>>
66 using Pair = std::pair<Key, Data>;
77 keys.
for_each([
this] (
auto & k) { this->
insert(make_pair(k, Data())); });
84 using Item_Type = Key;
86 using Value_Type = Data ;
91 static Data & get_data(
const Key & key) noexcept
93 return key_to_pair<Key, Data>(&
const_cast<Key&
>(key))->second;
96 static const Key & get_key(Data * data_ptr) noexcept
98 return data_to_pair<Key, Data>(data_ptr)->first;
112 Pair *
insert(
const Key & key,
const Data & data)
117 Pair *
insert(
const Key & key, Data && data = Data())
119 return this->
Base::insert(Pair(key, std::forward<Data>(data)));
122 Pair *
insert(Key && key,
const Data & data)
124 return this->
Base::insert(Pair(std::forward<Key>(key), data));
127 Pair *
insert(Key && key, Data && data = Data())
130 std::forward<Data>(data)));
133 Pair * append(
const Key & key,
const Data & data)
138 Pair * append(
const Key & key, Data && data = Data())
140 return this->
Base::insert(Pair(key, std::forward<Data>(data)));
143 Pair * append(Key && key,
const Data & data)
145 return this->
Base::insert(Pair(std::forward<Key>(key), data));
148 Pair * append(Key && key, Data && data = Data())
151 std::forward<Data>(data)));
165 Pair *
put(
const Key & key,
const Data & data)
170 Pair *
put(
const Key & key, Data && data)
172 return insert(key, std::forward<Data>(data));
175 Pair *
put(Key && key,
const Data & data)
177 return insert(std::forward<Key>(key), data);
180 Pair *
put(Key && key, Data && data)
182 return insert(std::forward<Key>(key), std::forward<Data>(data));
193 Data
remove(
const Key & key)
196 return this->
del(p).second;
199 Data
remove(Key && key)
201 return this->
del(forward<Key>(key), Data()).second;
214 Pair *
search(
const Key & key)
const noexcept
219 Pair *
search(Key && key)
const noexcept
224 bool has(
const Key & key)
const noexcept {
return search(key) !=
nullptr; }
226 bool has(Key && key)
const noexcept {
return search(move(key)) !=
nullptr; }
228 bool contains(
const Key & key)
const noexcept {
return has(key); }
230 bool contains(Key && key)
const noexcept {
return has(move(key)); }
244 return this->
Base::find(Pair(key, Data())).second;
247 const Data &
find(
const Key & key)
const 249 return this->
Base::find(Pair(key, Data())).second;
252 Data & operator [] (
const Key & key)
257 const Data & operator [] (
const Key & key)
const 259 return this->
find(key);
262 Data & operator [] (Key && key)
267 const Data & operator [] (Key && key)
const 269 return this->
find(move(key));
272 using Iterator =
typename Base::Iterator;
276 return this->
template maps<Key>([] (
auto p) {
return p.first; });
281 return this->
template maps<Data>([] (
auto p) {
return p.second; });
287 for (Iterator it(*
this); it.has_curr(); it.next_ne())
288 ret.
append(&it.get_curr_ne().second);
295 for (Iterator it(*
this); it.has_curr(); it.next_ne())
296 ret.
append(&it.get_curr_ne());
303 # include <tpl_binTree.H> 304 # include <tpl_avl.H> 305 # include <tpl_rb_tree.H> 306 # include <tpl_rand_tree.H> 307 # include <tpl_treap.H> 308 # include <tpl_treapRk.H> 309 # include <tpl_splay_tree.H> 318 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
327 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
335 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
346 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
356 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
367 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
377 template <
typename Key,
typename Type,
class Compare = Aleph::less<Key> >
381 template <
typename T,
class Op,
class C>
385 for (
auto it = c.get_it(); it.has_curr(); it.next_ne())
387 const auto & curr = it.get_curr_ne();
388 ret.
insert(curr, op(curr));
Pair * insert(const Key &key, const Data &data)
Definition: tpl_dynMapTree.H:112
Definition: tpl_dynMapTree.H:328
void for_each(Operation &operation) noexcept(noexcept(operation))
Definition: htlist.H:589
Definition: tpl_dynMapTree.H:62
Pair * put(const Key &key, const Data &data)
Definition: tpl_dynMapTree.H:165
Definition: tpl_dynMapTree.H:368
Definition: tpl_dynMapTree.H:347
Definition: tpl_dynMapTree.H:319
Definition: tpl_dynMapTree.H:336
Pair * search(const Key &key) const noexcept
Definition: tpl_dynMapTree.H:214
Definition: tpl_dynMapTree.H:378
Definition: tpl_dynMapTree.H:357
Definition: tpl_dynSetTree.H:61
std::pair< Key, Data > & find(const std::pair< Key, Data > &key) const
Definition: tpl_dynSetTree.H:414
std::pair< Key, Data > * search_or_insert(const std::pair< Key, Data > &key)
Definition: tpl_dynSetTree.H:254
T & append(const T &item)
Definition: htlist.H:1471
std::pair< Key, Data > del(const std::pair< Key, Data > &key)
Definition: tpl_dynSetTree.H:349
std::pair< Key, Data > * insert(const std::pair< Key, Data > &key)
Definition: tpl_dynSetTree.H:195
std::pair< Key, Data > * search(const std::pair< Key, Data > &key) const
Definition: tpl_dynSetTree.H:462
Data & find(const Key &key)
Definition: tpl_dynMapTree.H:242