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_hash.H
1 
2 # ifndef TPL_HASH_H
3 # define TPL_HASH_H
4 
5 # include <initializer_list>
6 # include <tpl_dynSetHash.H>
7 # include <tpl_dynSetOhash.H>
8 
9 namespace Aleph
10 {
11 
12 template <typename Key,
13  template <typename, class> class HashSetTable = ODhashTable,
14  class Cmp = Aleph::equal_to<Key>>
15 struct HashSet : public HashSetTable<Key, Cmp>
16 {
17  typedef HashSetTable<Key, Cmp> Base;
18  using Base::Base;
19 
20  void add (std::initializer_list<Key> l)
21  {
22  for (auto it = l.begin(); it != l.end(); it++)
23  this->insert(*it);
24  }
25 
26  HashSet(std::initializer_list<Key> l) : Base() { add(l); }
27 
28  HashSet() : Base() {}
29 };
30 
31 
32 template
33 <typename Key, typename Data,
34  template <typename, typename, class> class HashMapTable = ODhashTable,
36 struct HashMap : public HashMapTable<Key, Data, Cmp>
37 {
38  typedef HashMapTable<Key, Data, Cmp> Base;
39  using Base::Base;
40 
41  void add (std::initializer_list<Key> lk,
42  std::initializer_list<Data> ld)
43  {
44  if (lk.size() != ld.size())
45  throw std::range_error("size mismatch between domain and range");
46 
47  auto itk = lk.begin();
48  auto itd = ld.begin();
49  for (; itk != lk.end(); itk++, itd++)
50  this->insert(*itk, *itd);
51  }
52 
53  HashMap() : Base() {}
54 
55  HashMap(std::initializer_list<Key> lk,
56  std::initializer_list<Data> ld)
57  : Base()
58  {
59  add(lk, ld);
60  }
61 
62  template <template <typename T> class Container = DynList>
63  HashMap(const Container<Key> & c, std::initializer_list<Data> ld) : Base()
64  {
65  if (c.size() != ld.size())
66  throw std::range_error("size mismatch between domain and range");
67 
68  auto itd = ld.begin();
69  c.for_each(/* Lambda */ [this, &itd] (const Key & key)
70  {
71  set_entry(key, *itd++);
72  });
73  }
74 
75  Generate_Proxy_Operator(HashMap);
76 };
77 
78 
79 
80 
81 } // end namespace Aleph
82 
83 
84 # endif // TPL_HASH_H
Definition: tpl_hash.H:36
Definition: ahDry.H:523
Definition: tpl_hash.H:15
Definition: ahDry.H:13
Definition: ahFunction.H:115
Definition: tpl_odhash.H:53

Leandro Rabindranath León