Util--  1.1
table.hh
Go to the documentation of this file.
1 /* -*- C++ -*-
2  * $Id: table.hh 957 2005-03-07 16:01:20Z sjoyeux $
3  */
4 #ifndef UTILMM_UTILS_HASH_TABLE_HEADER
5 # define UTILMM_UTILS_HASH_TABLE_HEADER
6 
7 # include <utility>
8 # include <vector>
9 
11 
12 #include "utilmm/hash/hash_fwd.hh"
13 #include "utilmm/hash/bits/iter.hh"
14 
15 namespace utilmm {
16  namespace hash_toolbox {
17 
18  template<typename Value>
19  struct node {
20  explicit node(Value const &v, node *n=0);
21 
22  Value val;
24  }; // struct utilmm::hash_toolbox::node<>
25 
44  template<typename Key, typename Value,
45  class Extract, class Hash, class Equal>
46  class table {
47  public:
49  typedef Value value_type;
51  typedef Key key_type;
53  typedef size_t size_type;
54 
57 
58  private:
60  typedef std::vector<node_type *> bucket_type;
61 
62  public:
74 
79  table();
81  table(table const &);
82 
84  ~table();
85 
93  void swap(table &other);
95  table &operator= (table const &other);
96 
102  size_type size() const;
107  size_type max_size() const;
108 
116  bool empty() const;
117 
125  iterator begin();
133  iterator end();
134 
142  const_iterator begin() const;
150  const_iterator end() const;
151 
162  std::pair<iterator, iterator> equal_range(key_arg key);
167  std::pair< const_iterator,
168  const_iterator > equal_range(key_arg key) const;
169 
177  void erase(iterator const &first, iterator const &last);
178 
190  std::pair<iterator, bool> insert_unique(value_arg v);
200  iterator insert_multiple(value_arg v);
201 
206  void clear();
207 
208  private:
209  bucket_type bucket;
210  size_type node_count, avg_bucket_count;
211 
212  void resize(size_type size);
213 
214  node_type *insert(node_type **helper, value_arg v);
215 
216  static size_t hash_key(key_arg k, size_type mod);
217  static size_t hash_node(value_arg v, size_type mod);
218  static key_type const &get_key(value_arg v);
219 
220  static bucket_type copy_bucket(bucket_type const &other);
221 
222  size_t hash_node(value_arg v);
223 
224  node_type **find_node(key_arg k);
225  node_type *find_node(key_arg k) const;
226 
227  template<typename K, typename V, class Ex, class H, class Eq>
228  friend class iter;
229 
230  template<typename K, typename V, class Ex, class H, class Eq>
231  friend class const_iter;
232  }; // class utilmm::hash_toolbox::table<>
233 
234  } // namespace utilmm::hash_toolbox
235 } // namespace utilmm
236 
237 # define IN_UTILMM_UTILS_HASH_TABLE_HEADER
238 #include "utilmm/hash/bits/table.tcc"
239 # undef IN_UTILMM_UTILS_HASH_TABLE_HEADER
240 #endif // UTILMM_UTILS_HASH_TABLE_HEADER
241 
Definition of iterator for hash containers.
Value val
Definition: table.hh:22
const_iter< Key, Value, Extract, Hash, Equal > const_iterator
const iterator type
Definition: table.hh:73
node * next
Definition: table.hh:23
Hashing based table.
Definition: table.hh:46
arg_traits< value_type >::type value_arg
Definition: table.hh:55
Definition: table.hh:19
void swap(const S data, S &buffer)
Definition: endian.hh:46
size_t size_type
Size type.
Definition: table.hh:53
iter< Key, Value, Extract, Hash, Equal > iterator
iterator type
Definition: table.hh:67
Key key_type
Key type.
Definition: table.hh:51
Definition: auto_flag.hh:6
Definition of utilmm::arg_traits class.
node(Value const &v, node *n=0)
iterator for table
Definition: iter.hh:24
const iterator for table
Definition: iter.hh:38
computed_type type
argument type
Definition: arg_traits.hh:38
Forward declaration of utilmm::hash.
Value value_type
Value type for cells.
Definition: table.hh:49
arg_traits< key_type >::type key_arg
Definition: table.hh:56

Generated on Mon Sep 24 2018 17:06:40 for Util-- by doxygen 1.8.13
SourceForge.net Project Page