DDD 1.9.0.20250409152518
MLCache.hh
Go to the documentation of this file.
1#ifndef _MLCACHE_HH_
2#define _MLCACHE_HH_
3
5
6
7template
8 <
9 typename MLHomType
10 , typename NodeType
11 , typename HomNodeMapType
12 >
14{
15private:
16 mutable size_t peak_;
17
18 typedef typename hash_map< std::pair<MLHomType, NodeType>, HomNodeMapType >::type
21
22public:
23 MLCache () : peak_ (0) {};
24
26 void clear (bool keepstats = false) {
27 peak();
28 cache_.clear();
29 }
30
31 size_t peak () const {
32 size_t s = size();
33 if ( peak_ < s )
34 peak_ = s;
35 return peak_;
36 }
37
38
39 size_t size () const {
40 return cache_.size();
41 }
42
43 std::pair<bool,HomNodeMapType>
44 insert(const MLHomType& hom, const NodeType& node)
45 {
46 bool found;
47
48 { // lock on current bucket
49 typename hash_map::const_accessor access;
50 found = cache_.find ( access, std::make_pair(hom,node));
51 if (found)
52 return std::make_pair(false, access->second);
53 } // end of lock on the current bucket
54
55 // wasn't in cache
56 HomNodeMapType result = hom.eval(node);
57 // lock on current bucket
58 typename hash_map::accessor access;
59 bool insertion = cache_.insert ( access, std::make_pair(hom,node));
60 if (insertion) {
61 // should happen except in MT case
62 access->second = result;
63 }
64 return std::make_pair(insertion,result);
65 }
66
67#ifdef HASH_STAT
68 std::map<std::string, size_t> get_hits() const { return cache_.get_hits(); }
69 std::map<std::string, size_t> get_misses() const { return cache_.get_misses(); }
70 std::map<std::string, size_t> get_bounces() const { return cache_.get_bounces(); }
71#endif // HASH_STAT
72};
73
74#endif /* _MLCACHE_HH_ */
Definition MLCache.hh:14
void clear(bool keepstats=false)
clear the cache, discarding all values.
Definition MLCache.hh:26
hash_map cache_
Definition MLCache.hh:20
std::pair< bool, HomNodeMapType > insert(const MLHomType &hom, const NodeType &node)
Definition MLCache.hh:44
size_t peak_
Definition MLCache.hh:16
size_t peak() const
Definition MLCache.hh:31
MLCache()
Definition MLCache.hh:23
size_t size() const
Definition MLCache.hh:39
hash_map< std::pair< MLHomType, NodeType >, HomNodeMapType >::type hash_map
Definition MLCache.hh:19
Definition ext_hash_map.hh:96
Definition ext_hash_map.hh:38
Definition ext_hash_map.hh:21
size_type size() const
Definition ext_hash_map.hh:199
bool find(accessor &result, const Key &key)
Definition ext_hash_map.hh:217
bool insert(accessor &result, const Key &key)
Definition ext_hash_map.hh:235
void clear()
Definition ext_hash_map.hh:211

Please comment this page and report errors about it on the RefDocComments page.
Generated on Wed Apr 9 2025 15:27:42 for DDD by doxygen 1.9.8