Skip to content

hash_set const_iterator

Ned Bingham edited this page Mar 22, 2017 · 1 revision

std/has_set.h


hash_set

  • struct const_iterator

Points to an item in a hash set.

Member Types

  • typedef key_type type so that generic wrappers can access the parent container's key_type

Member Variables

  • 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.

Member Functions

Constructor

const_iterator()

The default constructor. root and loc are both set to NULL.

const_iterator(const hash_set<key_type, hash_func> *root, const end_item *loc)

This sets root and loc directly. It's protected member that should only be used by the parent container.

const_iterator(const const_iterator &copy)
const_iterator(const iterator &copy)

A copy constructor that sets root and loc.

Utility

operator bool() checks whether this iterator points to a valid item in the list.

Accessors

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.

const_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.

Iteration

const_iterator &operator++() Increments the iterator to the next item.

const_iterator &operator--() Decrements the iterator to the previous item.

const_iterator &operator+=(int n) Increments the iterator by n.

const_iterator &operator-=(int n) Decrements the iterator by n.

const_iterator operator+(int n) Returns the iterator n elements ahead of this one.

const_iterator operator-(int n) Returns the iterator n elements behind this one.

Comparison

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.

Modifiers

const_iterator &operator=(iterator i)
const_iterator &operator=(const_iterator i)

set the index of this iterator equal to the index of another.

Examples

#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>::const_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

Simple Containers

Standard Containers

Interface Containers

Specialized Containers

Input/Output

Algorithm

Clone this wiki locally