Aleph-w  1.5a.2
Biblioteca general de algoritmos y estructuras de datos
 Todo Clases Archivos Funciones Variables 'typedefs' Enumeraciones Amigas Grupos Páginas
tpl_dynMapTree.H
1 # ifndef TPL_DYNMAPTREE_H
2 # define TPL_DYNMAPTREE_H
3 
4 # include <tpl_dynSetTree.H>
5 
6 using namespace Aleph;
7 
8 namespace Aleph {
9 
32 template <
33  typename Key, typename Data,
34  template <typename, class> class Tree = Avl_Tree,
35  class Compare = Aleph::less<Key>>
36 class DynMapTree :
37 public DynSetTree<std::pair<Key, Data>, Tree, Dft_Pair_Cmp<Key, Data, Compare>>
38 {
39  typedef std::pair<Key, Data> Pair;
40 
42 
43 public:
44 
45  typedef Key Key_Type;
46 
47  typedef Key Item_Type;
48 
49  typedef Data Value_Type;
50 
51  using Base::Base;
52 
53  Data & get_data(const Key & key)
54  {
55  return key_to_pair<Key, Data>(&const_cast<Key&>(key))->second;
56  }
57 
58  const Key & get_key(Data * data_ptr)
59  {
60  return data_to_pair<Key, Data>(data_ptr)->first;
61  }
62 
74  Key * insert(const Key & key, const Data & data)
75  {
76  Pair * p = this->Base::insert(Pair(key, data));
77  return p != NULL ? &p->first : NULL;
78  }
79 
80  Key * insert(const Key & key, Data && data = Data())
81  {
82  Pair * p = this->Base::insert(Pair(key, std::move(data)));
83  return p != NULL ? &p->first : NULL;
84  }
85 
86  Key * insert(Key && key, const Data & data)
87  {
88  Pair * p = this->Base::insert(Pair(std::move(key), data));
89  return p != NULL ? &p->first : NULL;
90  }
91 
92  Key * insert(Key && key, Data && data = Data())
93  {
94  Pair * p = this->Base::insert(Pair(std::move(key), std::move(data)));
95  return p != NULL ? &p->first : NULL;
96  }
97 
110  Key * search_or_insert(const Key & key, const Data & data)
111  {
112  return &this->Base::search_or_insert(Pair(key, data))->first;
113  }
114 
115  Data * search_or_insert(const Key & key, Data && data)
116  {
117  return &this->Base::search_or_insert(Pair(key, std::move(data)))->first;
118  }
119 
120  Data * search_or_insert(Key && key, const Data & data)
121  {
122  return &this->Base::search_or_insert(Pair(std::move(key), data))->first;
123  }
124 
125  Data * search_or_insert(Key && key, Data && data)
126  {
127  return &search_or_insert(Pair(std::move(key), std::move(data)))->first;
128  }
129 
141  Key * put(const Key & key, const Data & data)
142  {
143  return insert(key, data);
144  }
145 
146  Key * put(const Key & key, Data && data)
147  {
148  return insert(key, std::move(data));
149  }
150 
151  Key * put(Key && key, const Data & data)
152  {
153  return insert(std::move(key), data);
154  }
155 
156  Key * put(Key && key, Data && data)
157  {
158  return insert(std::move(key), std::move(data));
159  }
160 
169  size_t remove(const Key & key)
170  {
171  return this->Base::remove(Pair(key, Data()));
172  }
173 
175  bool test_key(const Key & key) const
176  {
177  return this->Base::exist(Pair(key, Data()));
178  }
179 
180  bool has(const Key & key) const { return test_key(key); }
181 
191  Data * test(const Key & key)
192  {
193  Pair * p = this->Base::search(Pair(key, Data()));
194  return p != NULL ? &p->second : NULL;
195  }
196 
207  Data * search(const Key & key) const
208  {
209  Pair * p = this->Base::search(Pair(key, Data()));
210  return p != NULL ? &p->second : NULL;
211  }
212 
223  Data & find(const Key & key)
224  {
225  return this->Base::find(Pair(key, Data())).second;
226  }
227 
228  Map_Sequences_Methods();
229 
230  Generate_Proxy_Operator(DynMapTree);
231 };
232 } // end namespace Aleph
233 
234 
235 # include <tpl_binTree.H>
236 # include <tpl_avl.H>
237 # include <tpl_rb_tree.H>
238 # include <tpl_rand_tree.H>
239 # include <tpl_treap.H>
240 # include <tpl_treapRk.H>
241 # include <tpl_splay_tree.H>
242 
243 namespace Aleph {
250  template <typename Key, typename Type, class Compare = Aleph::less<Key> >
251  class DynMapBinTree : public DynMapTree<Key, Type, BinTree, Compare> {};
252 
259  template <typename Key, typename Type, class Compare = Aleph::less<Key> >
260  class DynMapAvlTree : public DynMapTree<Key, Type, Avl_Tree, Compare> {};
267  template <typename Key, typename Type, class Compare = Aleph::less<Key> >
268  class DynMapRbTree : public DynMapTree<Key, Type, Rb_Tree, Compare>
269  { /* empty */ };
270 
278  template <typename Key, typename Type, class Compare = Aleph::less<Key> >
279  class DynMapRandTree : public DynMapTree<Key, Type, Rand_Tree, Compare>
280  { /* empty */ };
281 
288  template <typename Key, typename Type, class Compare = Aleph::less<Key> >
289  class DynMapTreap : public DynMapTree<Key, Type, Treap, Compare>
290  { /* empty */ };
291 
299  template <typename Key, typename Type, class Compare = Aleph::less<Key> >
300  class DynMapTreapRk : public DynMapTree<Key, Type, Treap_Rk, Compare>
301  { /* empty */ };
302 
309  template <typename Key, typename Type, class Compare = Aleph::less<Key> >
310  class DynMapSplayTree : public DynMapTree<Key, Type, Splay_Tree, Compare>
311  { /* empty */ };
312 
313 } // end namespace Aleph
314 
315 # endif /* TPL_DYNMAPTREE_H */
316 
Data * test(const Key &key)
Definition: tpl_dynMapTree.H:191
Definition: tpl_dynMapTree.H:260
size_t remove(const Key &key)
Definition: tpl_dynSetTree.H:274
Definition: ahFunction.H:145
Definition: tpl_dynMapTree.H:36
Key * search(const Key &key) const
Definition: tpl_dynSetTree.H:364
Key * search_or_insert(const Key &key, const Data &data)
Definition: tpl_dynMapTree.H:110
Key * put(const Key &key, const Data &data)
Definition: tpl_dynMapTree.H:141
Definition: tpl_dynMapTree.H:300
Definition: tpl_dynMapTree.H:279
Definition: tpl_dynMapTree.H:251
Definition: tpl_dynMapTree.H:268
Key & find(const Key &key)
Definition: tpl_dynSetTree.H:316
Definition: tpl_dynMapTree.H:310
Definition: tpl_dynMapTree.H:289
bool test_key(const Key &key) const
Retorna true si key está presente dentro del mapeo.
Definition: tpl_dynMapTree.H:175
bool exist(const Key &key) const
Retorna true si key pertenece al conjunto dinámico.
Definition: tpl_dynSetTree.H:287
Definition: tpl_dynSetTree.H:34
Definition: tpl_avl.H:573
Key * search_or_insert(const Key &key)
Definition: tpl_dynSetTree.H:225
Key * insert(const Key &key, const Data &data)
Definition: tpl_dynMapTree.H:74
Key * insert(const Key &key)
Definition: tpl_dynSetTree.H:177
Data * search(const Key &key) const
Definition: tpl_dynMapTree.H:207
Data & find(const Key &key)
Definition: tpl_dynMapTree.H:223

Leandro Rabindranath León