I have a class implementing data structure (some kind of hash map) with 3 vectors.
std::vector<uint64_t> keys; // storage of keys to values (actually hash values)
std::vector<int> values; // storage for values (some integer)
std::vector<bool> allocated; // vector of allocated elements
Each of the vectors have the same size (for example 8 elements)
It would look like this
keys: 32233 52263 0 22224 0 87222 65432 0
values: 234 44 0 43 0 78 98 0
allocated: 1 1 0 1 0 1 1 0
I would like to implement a custom iterator that can iterate over the allocated
vector and being able to return the corresponding value of the values vector and the
key of the keys vector. The empty spots (marked as 0 in the allocated vector) should be ignored as these spots are considered as free spots.
I thought I might be able to return a pair type of each iterated allocated spot, like std::pair< key, value >
or such so I would have they key as it->first
and the value as it->second
.
I really have no idea how to get a start on implementing this. Is this possible at all? Would be great if someone can give me small sample code. Maybe this is even more simple then I think.
Thanks in advance for your help!