proj home

Files   Classes   Functions   Hierarchy  

hashtable< T, HFN > Class Template Reference

General hash table where the client manages the memory of the bucket links. The client defines the hash function of type HFN. More...

#include <hashtable.h>

Inheritance diagram for hashtable< T, HFN >:
Collaboration diagram for hashtable< T, HFN >:

List of all members.

Public Types

typedef bucketlink< T > * blink

Public Member Functions

 hashtable (uintc bucketsize_, HFN fn_)
 Pre allocate memory requirements before use, do not put this class in a loop.
 ~hashtable ()
 Destructor releases the memory used.
 hashtable ()
 Construct in a bad state.
void construct (uintc bucketsize_)
 Resize the container - invalidates previous memory.
void insert (bucketlink< T > *x)
 Put a value into the hash table.
bucketlink< T > * insertInverse (T const &key) const
 Get the link to the data if it exists, else 0 returned.
boolc remove (T const &key)
 Removes the bucket link which compared == with d.
boolc contains (T const &key) const
 Is the element in the hash table?

Public Attributes

uint bucketsize
 Size of vb.
HFN fn
 Hash function.
bucketlink< T > ** vb
 Public if the client wishes to iterate linearly through the hash data structure, another property of hash tables.


Detailed Description

template<typename T, typename HFN>
class hashtable< T, HFN >

General hash table where the client manages the memory of the bucket links. The client defines the hash function of type HFN.

Interface for template HFN parameter
class HFN
{
  public:

    uintc operator()(uintc key) const;

};

Example
  string dict[] = { "abc", "nogo", "python" };
  uintc n(3);
  vector< bucketlink<string> > v(n);
  for (uint i=0; i<n; ++i)
    v[i] = bucketlink<string>(&dict[i]);

  uintc hashtablesize(70);
  stringhash h(32,8);
  hashtable<string,stringhash&> H(hashtablesize,h);

  for (uint i=0; i<n; ++i)
    H.insert( & v[i] );

Definition at line 40 of file hashtable.h.


Member Typedef Documentation

template<typename T, typename HFN>
typedef bucketlink<T>* hashtable< T, HFN >::blink

Definition at line 54 of file hashtable.h.


Constructor & Destructor Documentation

template<typename T, typename HFN>
hashtable< T, HFN >::hashtable ( uintc  bucketsize_,
HFN  fn_ 
)

Pre allocate memory requirements before use, do not put this class in a loop.

template<typename T, typename HFN>
hashtable< T, HFN >::~hashtable (  ) 

Destructor releases the memory used.

template<typename T, typename HFN>
hashtable< T, HFN >::hashtable (  )  [inline]

Construct in a bad state.

Definition at line 67 of file hashtable.h.

00067 { bucketsize=0; };


Member Function Documentation

template<typename T, typename HFN>
void hashtable< T, HFN >::construct ( uintc  bucketsize_  ) 

Resize the container - invalidates previous memory.

Referenced by cfcontainerhash::construct().

template<typename T, typename HFN>
boolc hashtable< T, HFN >::contains ( T const &  key  )  const [inline]

Is the element in the hash table?

Definition at line 85 of file hashtable.h.

Referenced by cfcontainerhash::add(), hashtabletest::test01(), and hashtabletest::test07().

00086     { return insertInverse(key)!=0; }

template<typename T, typename HFN>
void hashtable< T, HFN >::insert ( bucketlink< T > *  x  ) 

Put a value into the hash table.

The client manages the memory of x.

Referenced by cfcontainerhash::add(), hashtabletest::test01(), hashtabletest::test02unit(), hashtabletest::test05(), hashtabletest::test06(), and hashtabletest::test07().

template<typename T, typename HFN>
bucketlink<T>* hashtable< T, HFN >::insertInverse ( T const &  key  )  const

Get the link to the data if it exists, else 0 returned.

The client can potentially modify the data (and corrupt this entry), so only modify non-key attributes.

Referenced by hashtable< sp, sph & >::contains(), cfcontainerhash::operator[](), hashtabletest::test01(), and hashtabletest::test02unit().

template<typename T, typename HFN>
boolc hashtable< T, HFN >::remove ( T const &  key  ) 

Removes the bucket link which compared == with d.

Referenced by cfcontainerhash::remove(), and hashtabletest::test07().


Member Data Documentation

template<typename T, typename HFN>
uint hashtable< T, HFN >::bucketsize

template<typename T, typename HFN>
HFN hashtable< T, HFN >::fn

Hash function.

Definition at line 47 of file hashtable.h.

Referenced by hashtable< T, HFN >::insert().

template<typename T, typename HFN>
bucketlink<T>* * hashtable< T, HFN >::vb

Public if the client wishes to iterate linearly through the hash data structure, another property of hash tables.

Definition at line 52 of file hashtable.h.

Referenced by hashtable< T, HFN >::construct(), hashtable< T, HFN >::insert(), hashtabletest::test05(), and hashtable< T, HFN >::~hashtable().


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

Generated on Fri Mar 4 00:50:02 2011 for Chelton Evans Source by  doxygen 1.5.8