ModErn Text Analysis
META Enumerates Textual Applications
probe_map.h
Go to the documentation of this file.
1 
10 #ifndef META_HASHING_PROBE_MAP_H_
11 #define META_HASHING_PROBE_MAP_H_
12 
13 #include "meta/config.h"
14 #include "meta/hashing/hash.h"
16 #include "meta/hashing/probing.h"
17 
18 namespace meta
19 {
20 namespace hashing
21 {
22 
37 template <class Key, class Value, class ProbingStrategy = probing::binary,
38  class Hash = hash<>, class KeyEqual = std::equal_to<Key>,
39  class Traits = hash_traits<kv_pair<Key, Value>>>
40 class probe_map
41  : private Traits::template storage_type<ProbingStrategy, Hash, KeyEqual>
42 {
43  public:
44  using storage_type =
45  typename Traits::template storage_type<ProbingStrategy, Hash, KeyEqual>;
46 
47  using typename storage_type::iterator;
48  using typename storage_type::const_iterator;
49 
50  using storage_type::default_max_load_factor;
51  using storage_type::default_resize_ratio;
52 
53  using storage_type::storage_type;
54  using storage_type::begin;
55  using storage_type::end;
56  using storage_type::max_load_factor;
57  using storage_type::resize_ratio;
58  using storage_type::emplace;
59  using storage_type::find;
60  using storage_type::empty;
61  using storage_type::next_load_factor;
62  using storage_type::next_size;
63  using storage_type::size;
64  using storage_type::capacity;
65  using storage_type::clear;
67  using storage_type::extract;
68 
69  probe_map() : storage_type{8}
70  {
71  // nothing
72  }
73 
74  iterator insert(const std::pair<Key, Value>& pr)
75  {
76  return emplace(pr);
77  }
78 
79  iterator insert(const Key& key, const Value& value)
80  {
81  return emplace(key, value);
82  }
83 
84  Value& operator[](const Key& key)
85  {
86  auto it = find(key);
87 
88  if (it == end())
89  it = emplace(key, Value{});
90 
91  return it->value();
92  }
93 
94  Value& operator[](Key&& key)
95  {
96  auto it = find(key);
97 
98  if (it == end())
99  it = emplace(std::move(key), Value{});
100 
101  return it->value();
102  }
103 
104  const Value& at(const Key& key) const
105  {
106  auto it = find(key);
107  if (it == end())
108  throw std::out_of_range{"invalid key"};
109 
110  return it->value();
111  }
112 
113  Value& at(const Key& key)
114  {
115  auto it = find(key);
116  if (it == end())
117  throw std::out_of_range{"invalid key"};
118 
119  return it->value();
120  }
121 };
122 }
123 }
124 #endif
uint64_t bytes_used(const T &elem, typename std::enable_if< std::is_same< T, std::string >::value >::type *=nullptr)
Gets the bytes used by a std::string.
Definition: postings_buffer.h:33
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retrieval, data mining, and other applications of text processing.
Definition: analyzer.h:25
An insert-only probing hash table.
Definition: probe_map.h:40