@@ -5,15 +5,15 @@ Module: cached_map
5
5
6
6
7
7
Purpose:
8
- A map-like data structure that unloads elements using a map_serializert when
8
+ A map-like data structure that unloads elements using a virtual_mapt when
9
9
there are more than a specified number of elements in memory.
10
10
11
11
\*******************************************************************/
12
12
13
13
#ifndef CPROVER_UTIL_CACHED_MAP_H
14
14
#define CPROVER_UTIL_CACHED_MAP_H
15
15
16
- #include " map_serializer .h"
16
+ #include " virtual_map .h"
17
17
#include " range_union.h"
18
18
#include < memory>
19
19
#include < functional>
@@ -36,13 +36,13 @@ Template parameters:
36
36
Purpose:
37
37
A map that caches the most recently used max_size entries in memory and
38
38
virtualizes the rest to a backing store.
39
- Neither the map_serializert passed at construction, nor any other
40
- map_serializert pointing at the same backing store should be used to update
39
+ Neither the virtual_mapt passed at construction, nor any other
40
+ virtual_mapt pointing at the same backing store should be used to update
41
41
values in the backing store used by the cached_mapt while the latter has
42
42
cached objects. The cached objects can be cleared with unload_all.
43
43
44
44
Remarks:
45
- The map_serializert must be kept in scope for the life of the cached_mapt.
45
+ The virtual_mapt must be kept in scope for the life of the cached_mapt.
46
46
This class could be improved in a couple of ways:
47
47
1) Keep track of the size of objects rather than the count of objects using a
48
48
user-provided get_element_size function and limit the cache to a memory
@@ -74,10 +74,10 @@ class cached_mapt final
74
74
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
75
75
typedef const value_type * const_pointer;
76
76
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
77
- typedef typename map_serializert <keyt, valuet>::size_type size_type;
77
+ typedef typename virtual_mapt <keyt, valuet>::size_type size_type;
78
78
79
79
private:
80
- map_serializert <keyt, valuet> &serializer ;
80
+ virtual_mapt <keyt, valuet> &base_map ;
81
81
mutable std::map<keyt, valuet> cache;
82
82
mutable std::map<valuet *, keyt> key_from_ptr;
83
83
mutable std::map<keyt, std::weak_ptr<valuet>> locked;
@@ -94,8 +94,8 @@ class cached_mapt final
94
94
Function: cached_mapt::cached_mapt
95
95
96
96
Inputs:
97
- serializer :
98
- The map_serializert that provides access to the backing store for the
97
+ base_map :
98
+ The virtual_mapt that provides access to the backing store for the
99
99
cached_mapt. This must be kept in scope for the life of the cached_mapt.
100
100
101
101
Outputs:
@@ -104,8 +104,8 @@ class cached_mapt final
104
104
Creates a cached_mapt with unlimited size.
105
105
106
106
\*******************************************************************/
107
- explicit cached_mapt (map_serializert <keyt, valuet> &serializer )
108
- : serializer(serializer )
107
+ explicit cached_mapt (virtual_mapt <keyt, valuet> &base_map )
108
+ : base_map(base_map )
109
109
{
110
110
}
111
111
@@ -114,8 +114,8 @@ class cached_mapt final
114
114
Function: cached_mapt::cached_mapt
115
115
116
116
Inputs:
117
- serializer :
118
- The map_serializert that provides access to the backing store for the
117
+ base_map :
118
+ The virtual_mapt that provides access to the backing store for the
119
119
cached_mapt. This must be kept in scope for the life of the cached_mapt.
120
120
max_size:
121
121
The maximum size limit of the cache, EXCEPT when more items than this are
@@ -127,10 +127,10 @@ class cached_mapt final
127
127
Creates a cached_mapt.
128
128
129
129
\*******************************************************************/
130
- explicit cached_mapt (
131
- map_serializert <keyt, valuet> &serializer ,
130
+ cached_mapt (
131
+ virtual_mapt <keyt, valuet> &base_map ,
132
132
size_t max_size)
133
- : serializer(serializer ), max_size(max_size)
133
+ : base_map(base_map ), max_size(max_size)
134
134
{
135
135
}
136
136
@@ -214,11 +214,11 @@ class cached_mapt final
214
214
This function checks the existence on disc of each item in the map.
215
215
216
216
\*******************************************************************/
217
- typename map_serializert <keyt, valuet>::keys_ranget keys () const
217
+ typename virtual_mapt <keyt, valuet>::keys_ranget keys () const
218
218
{
219
219
// Need to remove duplicates
220
220
return range_union (
221
- serializer .keys (),
221
+ base_map .keys (),
222
222
cache | boost::adaptors::map_keys);
223
223
}
224
224
@@ -253,7 +253,7 @@ class cached_mapt final
253
253
254
254
private:
255
255
typedef constify<cached_mapt> &cached_map_reft;
256
- typedef typename map_serializert <keyt, valuet>::keys_ranget::iterator
256
+ typedef typename virtual_mapt <keyt, valuet>::keys_ranget::iterator
257
257
key_iteratort;
258
258
259
259
private:
@@ -363,7 +363,7 @@ class cached_mapt final
363
363
\*******************************************************************/
364
364
bool contains (const keyt &key) const
365
365
{
366
- return cache.count (key) != 0 || serializer .contains (key);
366
+ return cache.count (key) != 0 || base_map .contains (key);
367
367
}
368
368
369
369
/* ******************************************************************\
@@ -416,7 +416,7 @@ class cached_mapt final
416
416
return get (
417
417
key,
418
418
[this , &key]
419
- { return serializer .contains (key) ? serializer .at (key) : valuet (); });
419
+ { return base_map .contains (key) ? base_map .at (key) : valuet (); });
420
420
}
421
421
422
422
/* ******************************************************************\
@@ -437,7 +437,7 @@ class cached_mapt final
437
437
{
438
438
return get (
439
439
key,
440
- [this , &key] { return serializer .at (key); });
440
+ [this , &key] { return base_map .at (key); });
441
441
}
442
442
443
443
/* ******************************************************************\
@@ -464,7 +464,7 @@ class cached_mapt final
464
464
return false ;
465
465
if (cache.count (key) != 0 )
466
466
remove_cache (key);
467
- serializer .remove (key);
467
+ base_map .remove (key);
468
468
return true ;
469
469
}
470
470
@@ -493,7 +493,7 @@ class cached_mapt final
493
493
key_from_ptr.clear ();
494
494
unloadable.clear ();
495
495
// Clear the backing store
496
- serializer .clear ();
496
+ base_map .clear ();
497
497
return true ;
498
498
}
499
499
@@ -538,8 +538,8 @@ class cached_mapt final
538
538
void flush ()
539
539
{
540
540
for (std::pair<const keyt, valuet> &elt : cache)
541
- serializer .set (elt.first , elt.second );
542
- serializer .flush ();
541
+ base_map .set (elt.first , elt.second );
542
+ base_map .flush ();
543
543
}
544
544
545
545
private:
@@ -595,7 +595,7 @@ class cached_mapt final
595
595
// Save any changes made while it was locked
596
596
// This may double save if flush was called
597
597
// This may save unnecessarily if the element wasn't changed while locked
598
- serializer .set (key, cache.at (key));
598
+ base_map .set (key, cache.at (key));
599
599
remove_cache (key);
600
600
}
601
601
0 commit comments