ModErn Text Analysis
META Enumerates Textual Applications
shard_cache.h
Go to the documentation of this file.
1 
10 #ifndef META_SHARD_CACHE_H_
11 #define META_SHARD_CACHE_H_
12 
13 #include <mutex>
14 #include <vector>
15 
16 #include "caching/dblru_cache.h"
17 #include "caching/splay_cache.h"
18 #include "util/optional.h"
19 
20 namespace meta
21 {
22 namespace caching
23 {
24 
31 template <class Key, class Value, template <class, class> class Map>
33 {
34  public:
43  template <class... Args>
44  generic_shard_cache(uint8_t shards, Args&&... args);
45 
49  generic_shard_cache(generic_shard_cache&&) = default;
50 
54  generic_shard_cache& operator=(generic_shard_cache&&) = default;
55 
59  ~generic_shard_cache() = default;
60 
66  void insert(const Key& key, const Value& value);
67 
75  util::optional<Value> find(const Key& key);
76 
77  private:
81  std::vector<Map<Key, Value>> shards_;
82 
87  std::hash<Key> hasher_;
88 };
89 
93 template <class Key, class Value>
95 
99 template <class Key, class Value>
101 }
102 }
103 
104 #include "caching/shard_cache.tcc"
105 #endif
std::hash< Key > hasher_
The hash function used for determining which shard a key belongs to.
Definition: shard_cache.h:87
util::optional< Value > find(const Key &key)
Finds a value in the cache.
Definition: shard_cache.tcc:30
generic_shard_cache(uint8_t shards, Args &&...args)
Constructs a shard cache with the given number of shards, passing any additional parameters to the un...
Definition: shard_cache.tcc:14
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
A simple sharding-based approach for increasing concurrency within a cache.
Definition: shard_cache.h:32
~generic_shard_cache()=default
Default destructor.
void insert(const Key &key, const Value &value)
Inserts a given (key, value) pair into the cache.
Definition: shard_cache.tcc:22
std::vector< Map< Key, Value > > shards_
The Map for each shard.
Definition: shard_cache.h:81
generic_shard_cache & operator=(generic_shard_cache &&)=default
generic_shard_cache may be move assigned