Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

HashSet Class Reference

HashSet with 2^n slots. More...

#include <HashSet.hpp>

List of all members.

Classes

struct  Data

Public Member Functions

 HashSet (unsigned bits)
 Constructs a hashset with 2^bits slots.
 HashSet (const HashSet &other)
 Copy constructor.
 ~HashSet ()
 Destructor.
unsigned bits () const
 Returns the lg2 of the number of slots.
unsigned size () const
 Returns the number of slots.
unsigned count () const
 Returns number of objects stored.
bool exists (hash_t key) const
 Returns true if key is in set.
void add (hash_t key)
 Adds a key.
void clear ()
 Clears the table.
void operator= (const HashSet &other)
 Copys other's data, overwriting everything in this table.

Private Member Functions

void CopyFrom (const HashSet &other)

Private Attributes

unsigned m_bits
 See bits().
unsigned m_size
 See size().
unsigned m_mask
 Equal to size() - 1.
unsigned m_count
 See count().
boost::scoped_array< int > m_used
 Index into m_allocated at which data for this slot is located; index is equal to EMPTY_SLOT if unused.
boost::scoped_array< Datam_allocated
 Allocated space for entries in the table.
std::vector< int > m_changelog
 History of slots that have been filled.

Static Private Attributes

static const int EMPTY_SLOT = -1

Detailed Description

HashSet with 2^n slots.

Deletes and dynamic resizing are not supported. Not thread-safe. Performs simple linear probing on hash collisions.

Uses a changelog for quick clears O(n) in number of added entries.

Definition at line 26 of file HashSet.hpp.


Constructor & Destructor Documentation

HashSet::HashSet ( unsigned  bits  )  [inline]

Constructs a hashset with 2^bits slots.

Definition at line 105 of file HashSet.hpp.

References EMPTY_SLOT, m_changelog, m_size, and m_used.

HashSet::HashSet ( const HashSet other  )  [inline]

Copy constructor.

Definition at line 119 of file HashSet.hpp.

References CopyFrom(), m_changelog, and m_size.

HashSet::~HashSet (  )  [inline]

Destructor.

Definition at line 132 of file HashSet.hpp.


Member Function Documentation

void HashSet::add ( hash_t  key  )  [inline]

Adds a key.

WILL ABORT IF TABLE IS FULL!

Issues a warning if table becomes 1/4th full.

Make sure the table is much larger (at least 4x larger) than the maximum amount of data you ever expect to store in this table. This is to reduce the number of probes on subsequent get() calls, as well as to avoid the need for dynamic resizing of the table.

Definition at line 173 of file HashSet.hpp.

References EMPTY_SLOT, hash_t, m_allocated, m_changelog, m_count, m_mask, m_size, and m_used.

unsigned HashSet::bits (  )  const [inline]

Returns the lg2 of the number of slots.

Definition at line 136 of file HashSet.hpp.

References m_bits.

void HashSet::clear (  )  [inline]

Clears the table.

Definition at line 201 of file HashSet.hpp.

References EMPTY_SLOT, m_changelog, m_count, and m_used.

void HashSet::CopyFrom ( const HashSet other  )  [inline, private]

Definition at line 209 of file HashSet.hpp.

References m_allocated, m_changelog, m_count, m_size, and m_used.

Referenced by HashSet(), and operator=().

unsigned HashSet::count (  )  const [inline]

Returns number of objects stored.

Definition at line 146 of file HashSet.hpp.

References m_count.

bool HashSet::exists ( hash_t  key  )  const [inline]

Returns true if key is in set.

Performs linear probing to find key.

Definition at line 152 of file HashSet.hpp.

References EMPTY_SLOT, hash_t, m_allocated, m_mask, m_size, and m_used.

void HashSet::operator= ( const HashSet other  )  [inline]

Copys other's data, overwriting everything in this table.

Definition at line 221 of file HashSet.hpp.

References CopyFrom().

unsigned HashSet::size (  )  const [inline]

Returns the number of slots.

Definition at line 141 of file HashSet.hpp.

References m_size.


Member Data Documentation

const int HashSet::EMPTY_SLOT = -1 [static, private]

Definition at line 72 of file HashSet.hpp.

Referenced by add(), clear(), exists(), and HashSet().

boost::scoped_array<Data> HashSet::m_allocated [private]

Allocated space for entries in the table.

Definition at line 97 of file HashSet.hpp.

Referenced by add(), CopyFrom(), and exists().

unsigned HashSet::m_bits [private]

See bits().

Definition at line 80 of file HashSet.hpp.

Referenced by bits().

std::vector<int> HashSet::m_changelog [private]

History of slots that have been filled.

Definition at line 100 of file HashSet.hpp.

Referenced by add(), clear(), CopyFrom(), and HashSet().

unsigned HashSet::m_count [private]

See count().

Definition at line 89 of file HashSet.hpp.

Referenced by add(), clear(), CopyFrom(), and count().

unsigned HashSet::m_mask [private]

Equal to size() - 1.

Used for bitmasking operations.

Definition at line 86 of file HashSet.hpp.

Referenced by add(), and exists().

unsigned HashSet::m_size [private]

See size().

Definition at line 83 of file HashSet.hpp.

Referenced by add(), CopyFrom(), exists(), HashSet(), and size().

boost::scoped_array<int> HashSet::m_used [private]

Index into m_allocated at which data for this slot is located; index is equal to EMPTY_SLOT if unused.

Definition at line 94 of file HashSet.hpp.

Referenced by add(), clear(), CopyFrom(), exists(), and HashSet().


The documentation for this class was generated from the following file:


6 Jan 2011 Doxygen 1.6.3