mCRL2
Loading...
Searching...
No Matches
sim_hashtable.h
Go to the documentation of this file.
1// Author(s): Bas Ploeger
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
12
13/* This class implements a hash table for storing triples of unsigned
14 * integers. Triples can be added, removed and checked for presence.
15 * Note however that removing a triple does not free space and re-adding
16 * a removed triple does not reuse the previously removed entry but
17 * creates new entry.
18 * Hence, although this does not lead to incorrect results, this hash
19 * table implementation is intended for applications in which removed
20 * triples will never (or rarely) be added again. */
21
22#ifndef SIM_HASHTABLE_H
23#define SIM_HASHTABLE_H
24#include <cstddef>
25#include <vector>
26
27struct bucket2
28{
29 std::size_t x,y;
30 std::size_t next;
31};
32
33struct bucket3
34{
35 std::size_t x,y,z;
36 std::size_t next;
37};
38
40{
41 public:
42 hash_table2(std::size_t initsize);
44 void clear();
45 void add(std::size_t x,std::size_t y);
46 bool find(std::size_t x,std::size_t y);
47 void remove(std::size_t x,std::size_t y);
48
49 private:
50 std::vector<bucket2> buckets;
51 std::vector<std::size_t> table;
52 std::size_t mask;
53 std::size_t removed_count;
54 std::size_t hash(std::size_t x,std::size_t y);
55 std::size_t hfind(std::size_t h,std::size_t x,std::size_t y);
56 bool check_table();
57
59};
60
62{
63 public:
65 bool is_end()
66 {
67 return (bucket_it == hash_table->buckets.end());
68 }
69 void operator ++();
70 std::size_t get_x()
71 {
72 return bucket_it->x;
73 }
74 std::size_t get_y()
75 {
76 return bucket_it->y;
77 }
78 private:
79 std::vector<bucket2>::iterator bucket_it;
81};
82
83
85{
86 public:
87 hash_table3(std::size_t initsize);
89 void clear();
90 void add(std::size_t x,std::size_t y,std::size_t z);
91 bool find(std::size_t x,std::size_t y,std::size_t z);
92 void remove(std::size_t x,std::size_t y,std::size_t z);
93 std::size_t get_num_elements()
94 {
95 return buckets.size() - removed_count;
96 }
97
98 private:
99 std::vector<bucket3> buckets;
100 std::vector<std::size_t> table;
101 std::size_t mask;
102 std::size_t removed_count;
103 std::size_t hash(std::size_t x,std::size_t y,std::size_t z);
104 std::size_t hfind(std::size_t h,std::size_t x,std::size_t y,std::size_t z);
105 bool check_table();
106
108};
109
111{
112 public:
114 bool is_end()
115 {
116 return (bucket_it == end);
117 }
118 void operator ++();
119 std::size_t get_x()
120 {
121 return bucket_it->x;
122 }
123 std::size_t get_y()
124 {
125 return bucket_it->y;
126 }
127 std::size_t get_z()
128 {
129 return bucket_it->z;
130 }
131 void set(std::size_t i)
132 {
133 bucket_it = hash_table->buckets.begin() + i;
134 }
135 void set_end(std::size_t i)
136 {
137 end = hash_table->buckets.begin() + i;
138 }
139 private:
140 std::vector<bucket3>::iterator bucket_it;
141 std::vector<bucket3>::iterator end;
143};
144
145#endif
std::size_t get_x()
std::vector< bucket2 >::iterator bucket_it
hash_table2 * hash_table
std::size_t get_y()
std::vector< bucket2 > buckets
bool find(std::size_t x, std::size_t y)
std::size_t removed_count
void remove(std::size_t x, std::size_t y)
void add(std::size_t x, std::size_t y)
std::size_t mask
std::size_t hfind(std::size_t h, std::size_t x, std::size_t y)
std::vector< std::size_t > table
std::vector< bucket3 >::iterator bucket_it
void set_end(std::size_t i)
std::vector< bucket3 >::iterator end
hash_table3 * hash_table
void set(std::size_t i)
std::size_t mask
bool find(std::size_t x, std::size_t y, std::size_t z)
std::size_t get_num_elements()
void remove(std::size_t x, std::size_t y, std::size_t z)
void add(std::size_t x, std::size_t y, std::size_t z)
std::size_t removed_count
std::vector< bucket3 > buckets
std::size_t hfind(std::size_t h, std::size_t x, std::size_t y, std::size_t z)
std::vector< std::size_t > table
std::size_t next
std::size_t y
std::size_t x
std::size_t next
std::size_t z
std::size_t x
std::size_t y
#define hash(l, r, m)
Definition tree_set.cpp:23