24 #ifndef UNIQUETABLE_ID_H
25 #define UNIQUETABLE_ID_H
55 template<
typename T,
typename ID>
74 if (id1==0 || id2 == 0) {
92 typedef typename google::sparsetable<id_t>
refs_t;
126 index.push_back(NULL);
127 marks.push_back(
false);
142 pos = (size_t)
index[pos];
167 for(
size_t i = 0 ; i <
index.size() ; i++) {
190 if (
refs.size() <=
id) {
192 refs.resize((3*
id)/2);
193 assert(
refs.size() >
id);
211 assert(
refs.test(
id));
219 refs.set(
id, refc-1);
241 index.push_back(NULL);
242 table.set_deleted_key(0);
244 index.push_back(NULL);
248 marks.push_back(
false);
249 marks.push_back(
false);
269 typename table_t::const_iterator it =
table.find (tmpid);
273 if (it !=
table.end()) {
284 std::pair<typename table_t::iterator, bool>
ref=
table.insert(
id);
316 for (
typename refs_t::nonempty_iterator it =
refs.nonempty_begin() ; it !=
refs.nonempty_end() ; ++it ) {
323 newtable.set_deleted_key(0);
339 delete (T*)
index[
id];
357 std::map<std::string, size_t> get_hits()
const {
return table.get_hits(); }
358 std::map<std::string, size_t> get_misses()
const {
return table.get_misses(); }
359 std::map<std::string, size_t> get_bounces()
const {
return table.get_bounces(); }
Requirements on the contained type are to be cloneable, hashable and equality comparable.
Definition: UniqueTableId.hh:56
google::sparsetable< id_t > refs_t
a sparse table holding refcounts for ref'd objects.
Definition: UniqueTableId.hh:92
const T * resolve(const id_t &id) const
Definition: UniqueTableId.hh:253
UniqueTableId(size_t s=4096)
Provide an initial size for both hash and index tables.
Definition: UniqueTableId.hh:236
d3::hash_set< id_t, id_hash, id_compare >::type table_t
Typedef helps hide implementation type.
Definition: UniqueTableId.hh:86
refs_t refs
The reference counters for ref'd nodes. It is a sparse table that only stores values for non-zero ent...
Definition: UniqueTableId.hh:105
table_it begin() const
Definition: UniqueTableId.hh:225
void ref(const id_t &id)
Definition: UniqueTableId.hh:188
size_t peak_size()
Definition: UniqueTableId.hh:299
static UniqueTableId & instance()
Definition: UniqueTableId.hh:229
size_t peak_size_
Definition: UniqueTableId.hh:109
void garbage()
Definition: UniqueTableId.hh:306
void print_table(std::ostream &os) const
Definition: UniqueTableId.hh:150
void print_marked(std::ostream &os) const
Definition: UniqueTableId.hh:165
std::vector< const T * > indexes_t
The Indexes table stores the id to (unique) T* map.
Definition: UniqueTableId.hh:89
id_t head
The free list is stored hidden in the free space of the index table.
Definition: UniqueTableId.hh:103
void mark(const id_t &id)
Definition: UniqueTableId.hh:179
id_t next_id()
return the next free id, either collected from free_list or the newly allocated last position of the ...
Definition: UniqueTableId.hh:123
indexes_t index
The actual index table, resolution of object from Id is done with this.
Definition: UniqueTableId.hh:99
marks_t marks
The marking entries, a bitset.
Definition: UniqueTableId.hh:107
table_it end() const
Definition: UniqueTableId.hh:226
table_t::const_iterator table_it
Definition: UniqueTableId.hh:223
void print_free_list(std::ostream &os) const
Definition: UniqueTableId.hh:137
ID id_t
Definition: UniqueTableId.hh:57
void deref(const id_t &id)
Definition: UniqueTableId.hh:209
id_t operator()(const T &_g)
The application operator, returns the address of the value already in the table if it exists,...
Definition: UniqueTableId.hh:263
size_t size() const
Returns the current number of filled entries in the table.
Definition: UniqueTableId.hh:294
table_t table
The actual table, operations on the UniqueTable are delegated on this.
Definition: UniqueTableId.hh:97
void push(const id_t &id)
add a node to free list
Definition: UniqueTableId.hh:112
std::vector< bool > marks_t
A bitset to store marks on objects used for mark&sweep.
Definition: UniqueTableId.hh:94
Definition: UniqueTableId.hh:72
bool operator()(const id_t &id1, const id_t &id2) const
Definition: UniqueTableId.hh:73
Definition: UniqueTableId.hh:62
size_t operator()(const id_t &id) const
Definition: UniqueTableId.hh:63
google::sparse_hash_set< Key, Hash, Compare, Allocator > type
Definition: hash_set.hh:24
Definition: hash_support.hh:230