-
Notifications
You must be signed in to change notification settings - Fork 0
hash_set iterator
struct iterator
Points to an item in a hash set.
-
typedef key_type type
so that generic wrappers can access the parent container'skey_type
-
hash_set<key_type, hash_func> *root
is a pointer to the parent container. -
end_item *loc
is the item pointed to by this iterator.
iterator()
The default constructor. root
and loc
are both set to NULL
.
iterator(hash_set<key_type, hash_func> *root, end_item *loc)
This sets root
and loc
directly. It's protected member that should only be used by the parent container.
iterator(const iterator ©)
A copy constructor that sets root
and loc
.
operator bool()
checks whether this iterator points to a valid item in the list.
value_type &operator*()
returns this iterator's value.
value_type *operator->()
The dot operator for this iterator's value.
value_type *ptr()
returns a pointer to this iterator's value.
value_type &get()
returns this iterator's value.
iterator &ref()
This is a placeholder function. It just returns the same iterator.
int idx()
returns the current index of this iterator by iterating from the beginning of the list to this iterator and counting.
int hash()
returns the hash used to bucket this key.
int bucket()
returns the bucket number of this key.
iterator &operator++()
Increments the iterator to the next item.
iterator &operator--()
Decrements the iterator to the previous item.
iterator &operator+=(int n)
Increments the iterator by n
.
iterator &operator-=(int n)
Decrements the iterator by n
.
iterator operator+(int n)
Returns the iterator n
elements ahead of this one.
iterator operator-(int n)
Returns the iterator n
elements behind this one.
bool operator==(iterator i)
bool operator!=(iterator i)
bool operator==(const_iterator i)
bool operator!=(const_iterator i)
Comparison operations between iterators compares loc
.
int operator-(iterator i)
int operator-(const_iterator i)
Returns the number of elements between i
and this iterator by iterating from i
to this iterator and counting.
void drop(int n = 1)
If n
is positive, this deletes all of the elements in the range [this, this+n)
and the iterator is left pointing at the element that was at this+n
. If n
is negative, this deletes all of the elements in the range [this-n, this)
and the iterator is left unchanged, pointing at this
.
iterator &operator=(iterator i)
set the index of this iterator equal to the index of another.
#include <std/ascii_stream.h>
#include <std/hash_set.h>
using namespace core;
int main()
{
hash_set<int> h;
h.insert(5);
h.insert(8);
h.insert(20);
h.insert(31);
h.insert(72);
for (hash_set<int>::iterator i = h.begin(); i != h.end(); i++)
cout << i.idx() << ": " << *i << endl;
return 0;
}
0: 5
1: 20
2: 72
3: 31
4: 8