Skip to content

Commit 1ffdf87

Browse files
Renamed map_serializert to virtual_mapt
1 parent 835a6d2 commit 1ffdf87

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

src/util/cached_map.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Module: cached_map
55
66
77
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
99
there are more than a specified number of elements in memory.
1010
1111
\*******************************************************************/
1212

1313
#ifndef CPROVER_UTIL_CACHED_MAP_H
1414
#define CPROVER_UTIL_CACHED_MAP_H
1515

16-
#include "map_serializer.h"
16+
#include "virtual_map.h"
1717
#include "range_union.h"
1818
#include <memory>
1919
#include <functional>
@@ -36,13 +36,13 @@ Template parameters:
3636
Purpose:
3737
A map that caches the most recently used max_size entries in memory and
3838
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
4141
values in the backing store used by the cached_mapt while the latter has
4242
cached objects. The cached objects can be cleared with unload_all.
4343
4444
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.
4646
This class could be improved in a couple of ways:
4747
1) Keep track of the size of objects rather than the count of objects using a
4848
user-provided get_element_size function and limit the cache to a memory
@@ -74,10 +74,10 @@ class cached_mapt final
7474
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
7575
typedef const value_type * const_pointer;
7676
// 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;
7878

7979
private:
80-
map_serializert<keyt, valuet> &serializer;
80+
virtual_mapt<keyt, valuet> &base_map;
8181
mutable std::map<keyt, valuet> cache;
8282
mutable std::map<valuet *, keyt> key_from_ptr;
8383
mutable std::map<keyt, std::weak_ptr<valuet>> locked;
@@ -94,8 +94,8 @@ class cached_mapt final
9494
Function: cached_mapt::cached_mapt
9595
9696
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
9999
cached_mapt. This must be kept in scope for the life of the cached_mapt.
100100
101101
Outputs:
@@ -104,8 +104,8 @@ class cached_mapt final
104104
Creates a cached_mapt with unlimited size.
105105
106106
\*******************************************************************/
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)
109109
{
110110
}
111111

@@ -114,8 +114,8 @@ class cached_mapt final
114114
Function: cached_mapt::cached_mapt
115115
116116
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
119119
cached_mapt. This must be kept in scope for the life of the cached_mapt.
120120
max_size:
121121
The maximum size limit of the cache, EXCEPT when more items than this are
@@ -127,10 +127,10 @@ class cached_mapt final
127127
Creates a cached_mapt.
128128
129129
\*******************************************************************/
130-
explicit cached_mapt(
131-
map_serializert<keyt, valuet> &serializer,
130+
cached_mapt(
131+
virtual_mapt<keyt, valuet> &base_map,
132132
size_t max_size)
133-
: serializer(serializer), max_size(max_size)
133+
: base_map(base_map), max_size(max_size)
134134
{
135135
}
136136

@@ -214,11 +214,11 @@ class cached_mapt final
214214
This function checks the existence on disc of each item in the map.
215215
216216
\*******************************************************************/
217-
typename map_serializert<keyt, valuet>::keys_ranget keys() const
217+
typename virtual_mapt<keyt, valuet>::keys_ranget keys() const
218218
{
219219
// Need to remove duplicates
220220
return range_union(
221-
serializer.keys(),
221+
base_map.keys(),
222222
cache | boost::adaptors::map_keys);
223223
}
224224

@@ -253,7 +253,7 @@ class cached_mapt final
253253

254254
private:
255255
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
257257
key_iteratort;
258258

259259
private:
@@ -363,7 +363,7 @@ class cached_mapt final
363363
\*******************************************************************/
364364
bool contains(const keyt &key) const
365365
{
366-
return cache.count(key) != 0 || serializer.contains(key);
366+
return cache.count(key) != 0 || base_map.contains(key);
367367
}
368368

369369
/*******************************************************************\
@@ -416,7 +416,7 @@ class cached_mapt final
416416
return get(
417417
key,
418418
[this, &key]
419-
{ return serializer.contains(key) ? serializer.at(key) : valuet(); });
419+
{ return base_map.contains(key) ? base_map.at(key) : valuet(); });
420420
}
421421

422422
/*******************************************************************\
@@ -437,7 +437,7 @@ class cached_mapt final
437437
{
438438
return get(
439439
key,
440-
[this, &key] { return serializer.at(key); });
440+
[this, &key] { return base_map.at(key); });
441441
}
442442

443443
/*******************************************************************\
@@ -464,7 +464,7 @@ class cached_mapt final
464464
return false;
465465
if(cache.count(key) != 0)
466466
remove_cache(key);
467-
serializer.remove(key);
467+
base_map.remove(key);
468468
return true;
469469
}
470470

@@ -493,7 +493,7 @@ class cached_mapt final
493493
key_from_ptr.clear();
494494
unloadable.clear();
495495
// Clear the backing store
496-
serializer.clear();
496+
base_map.clear();
497497
return true;
498498
}
499499

@@ -538,8 +538,8 @@ class cached_mapt final
538538
void flush()
539539
{
540540
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();
543543
}
544544

545545
private:
@@ -595,7 +595,7 @@ class cached_mapt final
595595
// Save any changes made while it was locked
596596
// This may double save if flush was called
597597
// 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));
599599
remove_cache(key);
600600
}
601601

src/util/json_map_serializer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Purpose: Generic serialization of maps of object hierarchies to JSON.
1111
#ifndef CPROVER_UTIL_JSON_MAP_SERIALIZER_H
1212
#define CPROVER_UTIL_JSON_MAP_SERIALIZER_H
1313

14-
#include "map_serializer.h"
14+
#include "virtual_map.h"
1515
#include "json_serializer.h"
1616
#include <util/file_util.h>
1717
#include <cstdio>
@@ -37,7 +37,7 @@ Template parameters:
3737
3838
\*******************************************************************/
3939
template<typename keyt, typename valuet>
40-
class json_map_serializert:public map_serializert<keyt, valuet>
40+
class json_map_serializert:public virtual_mapt<keyt, valuet>
4141
{
4242
private:
4343
// This extension is added to all saved JSON files

src/util/map_serializer.h renamed to src/util/virtual_map.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/*******************************************************************\
22
3-
Module: map_serializer
3+
Module: virtual_map
44
55
66
7-
Purpose: Generic serialization of maps of object hierarchies.
7+
Purpose: Generic virtual maps.
88
99
\*******************************************************************/
1010

11-
#ifndef CPROVER_UTIL_MAP_SERIALIZER_H
12-
#define CPROVER_UTIL_MAP_SERIALIZER_H
11+
#ifndef CPROVER_UTIL_VIRTUAL_MAP_H
12+
#define CPROVER_UTIL_VIRTUAL_MAP_H
1313

1414
#include <boost/range/any_range.hpp>
1515

1616

1717
/*******************************************************************\
1818
19-
Class: map_serializert
19+
Class: virtual_mapt
2020
2121
Template parameters:
2222
keyt: The type of keys of the map.
23-
valuet: The type of values of the map. Must be serializable.
23+
valuet: The type of values of the map.
2424
2525
Purpose:
2626
Provides a map-like interface to a backing store such as JSON files or a
2727
database.
2828
2929
\*******************************************************************/
3030
template<typename keyt, typename valuet>
31-
class map_serializert
31+
class virtual_mapt
3232
{
3333
public:
3434
// NOLINTNEXTLINE(readability/identifiers) - name matches those used in STL
@@ -58,11 +58,11 @@ class map_serializert
5858
keys_ranget;
5959

6060
// The virtual destructor ensures sub-classes are disposed correctly.
61-
virtual ~map_serializert()=default;
61+
virtual ~virtual_mapt()=default;
6262

6363
/*******************************************************************\
6464
65-
Function: map_serializert::size
65+
Function: virtual_mapt::size
6666
6767
Inputs:
6868
@@ -77,7 +77,7 @@ class map_serializert
7777

7878
/*******************************************************************\
7979
80-
Function: map_serializert::keys
80+
Function: virtual_mapt::keys
8181
8282
Inputs:
8383
@@ -92,7 +92,7 @@ class map_serializert
9292

9393
/*******************************************************************\
9494
95-
Function: map_serializert::contains
95+
Function: virtual_mapt::contains
9696
9797
Inputs:
9898
key: The key to search for.
@@ -108,7 +108,7 @@ class map_serializert
108108

109109
/*******************************************************************\
110110
111-
Function: map_serializert::at
111+
Function: virtual_mapt::at
112112
113113
Inputs:
114114
key: The key to search for.
@@ -124,7 +124,7 @@ class map_serializert
124124

125125
/*******************************************************************\
126126
127-
Function: map_serializert::set
127+
Function: virtual_mapt::set
128128
129129
Inputs:
130130
key: The key of the key-value pair to add.
@@ -140,7 +140,7 @@ class map_serializert
140140

141141
/*******************************************************************\
142142
143-
Function: map_serializert::erase
143+
Function: virtual_mapt::erase
144144
145145
Inputs:
146146
key: The key of the key-value pair to remove.
@@ -155,7 +155,7 @@ class map_serializert
155155

156156
/*******************************************************************\
157157
158-
Function: map_serializert::clear
158+
Function: virtual_mapt::clear
159159
160160
Inputs:
161161
@@ -169,14 +169,14 @@ class map_serializert
169169

170170
/*******************************************************************\
171171
172-
Function: map_serializert::flush
172+
Function: virtual_mapt::flush
173173
174174
Inputs:
175175
176176
Outputs:
177177
178178
Purpose:
179-
Flushes cached data from the serializer to the backing store, if any.
179+
Flushes changes, if any.
180180
181181
\*******************************************************************/
182182
virtual void flush()=0;

0 commit comments

Comments
 (0)