Util--  1.1
hash_map.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * $Id: hash_map.hh 957 2005-03-07 16:01:20Z sjoyeux $
3  */
4 #ifndef UTILMM_HASH_MAP_HEADER
5 # define UTILMM_HASH_MAP_HEADER
6 #include "utilmm/config/config.h"
7 
9 
11 
12 namespace utilmm {
13 
29  template< typename Key, typename Data, class Hash = hash<Key>,
30  class Equal = std::equal_to<Key> >
31  class hash_map {
32  public:
34  typedef Key key_type;
39  typedef Data data_type;
47  typedef std::pair<Key const, Data> value_type;
48 
49  private:
51  Hash, Equal> container_type;
52  typedef typename container_type::value_arg value_arg;
53  typedef typename container_type::key_arg key_arg;
54 
55  container_type the_table;
56 
57  public:
68 
73  void swap(hash_map &other) {
74  the_table.swap(other.the_table);
75  }
76 
81  size_t size() const {
82  return the_table.size();
83  }
88  size_t max_size() const {
89  return the_table.max_size();
90  }
91 
96  bool empty() const {
97  return the_table.empty();
98  }
99 
104  iterator begin() {
105  return the_table.begin();
106  }
111  iterator end() {
112  return the_table.end();
113  }
118  const_iterator begin() const {
119  return the_table.begin();
120  }
125  const_iterator end() const {
126  return the_table.end();
127  }
128 
139  iterator find(key_arg key) {
140  return the_table.equal_range(key).first;
141  }
146  const_iterator find(key_arg key) const {
147  return the_table.equal_range(key).first;
148  }
149 
162  std::pair<iterator, bool> insert(value_arg val) {
163  return the_table.insert_unique(val);
164  }
165 
170  void erase(iterator const &first, iterator const &last) {
171  the_table.erase(first, last);
172  }
179  void erase(iterator const &i) {
180  if( end()!=i )
181  erase(i, i+1);
182  }
189  void erase(key_arg key) {
190  erase(find(key));
191  }
192 
197  void clear() {
198  the_table.clear();
199  }
200 
201  }; // class utilmm::hash_map<>
202 
203 } // namespace utilmm
204 
205 #endif // UTILMM_HASH_MAP_HEADER
206 
map with hashing access
Definition: hash_map.hh:31
std::pair< iterator, iterator > equal_range(key_arg key)
equality range
const_iterator begin() const
beginning of table
Definition: hash_map.hh:118
void swap(table &other)
swapping values function
void clear()
Remove all elements.
Definition: hash_map.hh:197
iterator find(key_arg key)
Search for key.
Definition: hash_map.hh:139
size_type max_size() const
max elmement number
void erase(iterator const &first, iterator const &last)
Remove elements.
void erase(iterator const &i)
Remove element.
Definition: hash_map.hh:179
Hashing based table.
Definition: table.hh:46
iterator end()
End of table.
size_type size() const
element count
iterator begin()
beginning of table
Definition: hash_map.hh:104
std::pair< Key const, Data > value_type
Value type for cells.
Definition: hash_map.hh:47
void clear()
remove all elements
bool empty() const
Emptyness test.
std::pair< iterator, bool > insert(value_arg val)
Cell insertion.
Definition: hash_map.hh:162
size_t max_size() const
max element number
Definition: hash_map.hh:88
bool empty() const
Emptyness test.
Definition: hash_map.hh:96
Data data_type
Data type.
Definition: hash_map.hh:39
std::pair< iterator, bool > insert_unique(value_arg v)
Unique key insertion.
Key key_type
Key type.
Definition: hash_map.hh:34
iterator begin()
Beginning of table.
container_type::iterator iterator
iterator type
Definition: hash_map.hh:62
Definition: auto_flag.hh:6
void swap(hash_map &other)
swapping function
Definition: hash_map.hh:73
iterator for table
Definition: iter.hh:24
const iterator for table
Definition: iter.hh:38
const_iterator end() const
end of table
Definition: hash_map.hh:125
Declaration of utilmm::hash_toolbox::table.
iterator end()
end of table
Definition: hash_map.hh:111
container_type::const_iterator const_iterator
const iterator type
Definition: hash_map.hh:67
const_iterator find(key_arg key) const
Search key.
Definition: hash_map.hh:146
size_t size() const
element count
Definition: hash_map.hh:81
void erase(iterator const &first, iterator const &last)
Remove range.
Definition: hash_map.hh:170
Som usefull functors.
void erase(key_arg key)
remove element
Definition: hash_map.hh:189

Generated on Wed Oct 17 2018 09:34:19 for Util-- by doxygen 1.8.13
SourceForge.net Project Page