OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HashTableCache< K, V > Class Template Reference

#include <HashTableCache.h>

+ Inheritance diagram for HashTableCache< K, V >:

Public Member Functions

 HashTableCache ()
 
std::function< void()> getCacheInvalidator ()
 
getCachedHashTable (const size_t idx)
 
size_t getNumberOfCachedHashTables ()
 
void clear ()
 
void insert (const K &key, V &hash_table)
 
std::optional< V > get (const K &key)
 

Protected Attributes

std::vector< std::pair< K, V > > contents_
 
std::mutex mutex_
 

Detailed Description

template<class K, class V>
class HashTableCache< K, V >

Definition at line 26 of file HashTableCache.h.

Constructor & Destructor Documentation

template<class K , class V >
HashTableCache< K, V >::HashTableCache ( )
inline

Definition at line 28 of file HashTableCache.h.

28 {}

Member Function Documentation

template<class K , class V >
void HashTableCache< K, V >::clear ( )
inline

Definition at line 49 of file HashTableCache.h.

References HashTableCache< K, V >::contents_, and HashTableCache< K, V >::mutex_.

49  {
50  std::lock_guard<std::mutex> guard(mutex_);
51  contents_.clear();
52  }
std::mutex mutex_
std::vector< std::pair< K, V > > contents_
template<class K , class V >
std::optional<V> HashTableCache< K, V >::get ( const K &  key)
inline

Definition at line 67 of file HashTableCache.h.

References HashTableCache< K, V >::contents_, and HashTableCache< K, V >::mutex_.

67  {
68  std::lock_guard<std::mutex> guard(mutex_);
69  for (const auto& kv : contents_) {
70  if (kv.first == key) {
71  return kv.second;
72  }
73  }
74  return std::nullopt;
75  }
std::mutex mutex_
std::vector< std::pair< K, V > > contents_
template<class K , class V >
V HashTableCache< K, V >::getCachedHashTable ( const size_t  idx)
inline

Definition at line 38 of file HashTableCache.h.

References CHECK_LT, HashTableCache< K, V >::contents_, and HashTableCache< K, V >::mutex_.

38  {
39  std::lock_guard<std::mutex> guard(mutex_);
40  CHECK_LT(idx, contents_.size());
41  return contents_.at(idx).second;
42  }
#define CHECK_LT(x, y)
Definition: Logger.h:216
std::mutex mutex_
std::vector< std::pair< K, V > > contents_
template<class K , class V >
std::function<void()> HashTableCache< K, V >::getCacheInvalidator ( )
inline

Definition at line 30 of file HashTableCache.h.

References HashTableCache< K, V >::contents_, HashTableCache< K, V >::mutex_, and VLOG.

30  {
31  return [this]() -> void {
32  std::lock_guard<std::mutex> guard(mutex_);
33  VLOG(1) << "Invalidating " << contents_.size() << " cached hash tables.";
34  contents_.clear();
35  };
36  }
std::mutex mutex_
std::vector< std::pair< K, V > > contents_
#define VLOG(n)
Definition: Logger.h:300
template<class K , class V >
size_t HashTableCache< K, V >::getNumberOfCachedHashTables ( )
inline

Definition at line 44 of file HashTableCache.h.

References HashTableCache< K, V >::contents_, and HashTableCache< K, V >::mutex_.

44  {
45  std::lock_guard<std::mutex> guard(mutex_);
46  return contents_.size();
47  }
std::mutex mutex_
std::vector< std::pair< K, V > > contents_
template<class K , class V >
void HashTableCache< K, V >::insert ( const K &  key,
V &  hash_table 
)
inline

Definition at line 54 of file HashTableCache.h.

References HashTableCache< K, V >::contents_, and HashTableCache< K, V >::mutex_.

54  {
55  std::lock_guard<std::mutex> guard(mutex_);
56  for (auto& kv : contents_) {
57  if (kv.first == key) {
58  auto& cached_hash_table = kv.second;
59  cached_hash_table = hash_table;
60  return;
61  }
62  }
63  contents_.emplace_back(key, hash_table);
64  }
std::mutex mutex_
std::vector< std::pair< K, V > > contents_

Member Data Documentation


The documentation for this class was generated from the following file: