ModErn Text Analysis
META Enumerates Textual Applications
hash_traits.h
Go to the documentation of this file.
1 
6 #ifndef META_HASHING_HASH_TRAITS_H_
7 #define META_HASHING_HASH_TRAITS_H_
8 
9 #include <limits>
10 #include <string>
11 #include <type_traits>
12 #include <utility>
13 
14 #include "meta/config.h"
16 
17 namespace meta
18 {
19 namespace hashing
20 {
21 
38 template <class T>
39 struct key_traits
40 {
41  static constexpr bool inlineable = std::is_integral<T>::value;
42 
43  constexpr static T sentinel()
44  {
45  return std::numeric_limits<T>::max();
46  }
47 };
48 
63 template <class T>
65 {
66  template <class ProbingStrategy, class Hash, class KeyEqual>
67  using storage_type =
68  typename std::conditional<key_traits<T>::inlineable,
69  inline_key_storage<T, ProbingStrategy, Hash,
70  KeyEqual>,
71  external_key_storage<T, ProbingStrategy, Hash,
72  KeyEqual>>::type;
73 
74  using probe_entry =
75  typename std::conditional<key_traits<T>::inlineable, T, hash_idx>::type;
76 };
77 
98 template <class K, class V>
99 struct hash_traits<kv_pair<K, V>>
100 {
101  template <class ProbingStrategy, class Hash, class KeyEqual>
102  using key_inlineable_storage = typename std::
103  conditional<sizeof(V) <= 8,
104  inline_key_value_storage<K, V, ProbingStrategy, Hash,
105  KeyEqual>,
106  inline_key_external_value_storage<K, V, ProbingStrategy,
107  Hash, KeyEqual>>::type;
108 
109  template <class ProbingStrategy, class Hash, class KeyEqual>
110  using storage_type = typename std::
111  conditional<key_traits<K>::inlineable,
112  key_inlineable_storage<ProbingStrategy, Hash, KeyEqual>,
113  external_key_value_storage<K, V, ProbingStrategy, Hash,
114  KeyEqual>>::type;
115 
116  using key_inlineable_probe_entry =
117  typename std::conditional<sizeof(V) <= 8, std::pair<K, V>,
118  std::pair<K, std::size_t>>::type;
119 
120  using probe_entry =
121  typename std::conditional<key_traits<K>::inlineable,
122  key_inlineable_probe_entry, hash_idx>::type;
123 };
124 }
125 }
126 #endif
Storage class for hash tables with key, value pairs that should be stored externally from the probing...
Definition: hash_storage.h:1121
Storage class for hash tables with keys that can be inlined into the probing table, but values that should be stored externally.
Definition: hash_storage.h:968
Storage class for hash sets that have non-inlineable keys.
Definition: hash_storage.h:575
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
Used by probing arrays where keys (and possibly values) are stored externally from the probing array ...
Definition: hash_storage.h:356
Storage class for hash sets with keys that can be inlined into the probing table. ...
Definition: hash_storage.h:702
A traits class for types that may be used as keys or values in the probing hash tables.
Definition: hash_traits.h:64
Pair class used by the hash tables.
Definition: hash_storage.h:35
Storage class for hash tables with keys and values that can both be inlined into the probing table...
Definition: hash_storage.h:830