6 #ifndef TURI_HASH_MAP_CONTAINER_H_ 7 #define TURI_HASH_MAP_CONTAINER_H_ 9 #include <core/parallel/pthread_tools.hpp> 10 #include <core/util/cityhash_tc.hpp> 14 template <
typename K,
typename V>
15 class EXPORT hash_map;
18 template <
typename K,
typename V>
19 class EXPORT hash_map_container {
21 typedef hash_map<K, V> hash_map_type;
24 hash_map_container() {
26 maps.resize(num_segments, hash_map_type());
29 explicit hash_map_container(
size_t num_seg) {
32 maps.resize(num_segments, hash_map_type());
35 hash_map_container(
const hash_map_container<K, V>&) =
default;
36 hash_map_container& operator=(
const hash_map_container<K, V>&) =
default;
39 void update(
const K& k,
const std::function<
void (V&)>& func) {
40 size_t seg_id = get_segment_id(k);
41 maps[seg_id].update(k, func);
44 const V&
get(
const K& k)
const {
45 size_t seg_id = get_segment_id(k);
46 return maps[seg_id].get(k);
49 inline size_t get_segment_id(
const K& k)
const {
50 return hash64(k) % num_segments;
60 oarc << num_segments << maps;
64 iarc >> num_segments >> maps;
68 std::vector<hash_map_type> maps;
71 template <
typename K,
typename V>
72 class EXPORT hash_map {
76 hash_map(
const hash_map& oth) {
80 hash_map& operator=(
const hash_map& oth) {
85 void update(
const K& k,
const std::function<
void (V&)>& func) {
87 auto fit = umap.find(k);
88 if (fit == umap.end()) {
89 fit = umap.insert(std::make_pair(k, default_value)).first;
95 const V&
get(
const K& k)
const {
96 auto fit = umap.find(k);
97 if (fit == umap.end()) {
119 std::unordered_map<K, V> umap;
120 V default_value = V();
125 #endif // TURI_HASH_MAP_CONTAINER_H_ The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
static size_t cpu_count()
static uint64_t hash64(const char *s, size_t len)
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.