Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
HashTable< T, H, A > Class Template Reference

#include <elm/data/HashTable.h>

+ Inheritance diagram for HashTable< T, H, A >:

Classes

class  Iter
 

Public Types

typedef HashTable< T, H, A > self_t
 

Public Member Functions

 HashTable (int _size=211)
 
 HashTable (const self_t &h)
 
 ~HashTable (void)
 
const H & hash () const
 
H & hash ()
 
const A & allocator () const
 
A & allocator ()
 
const T * get (const T &key) const
 
const T * get_const (const T &key) const
 
bool hasKey (const T &key) const
 
bool hasKey_const (const T &key) const
 
bool exists (const T &key) const
 
bool exists_const (const T &key) const
 
void put (const T &data)
 
template<class CC >
void putAll (const CC &c)
 
bool isEmpty (void) const
 
 operator bool () const
 
int count (void) const
 
bool contains (const T &x) const
 
bool contains_const (const T &x) const
 
template<class CC >
bool containsAll (const CC &c) const
 
template<class CC >
bool containsAll_const (const CC &c) const
 
Iter begin () const
 
Iter end () const
 
bool equals (const HashTable< T > &h) const
 
bool equals_const (const HashTable< T > &h) const
 
bool operator== (const HashTable< T > &t) const
 
bool operator!= (const HashTable< T > &t) const
 
void clear (void)
 
T * add (const T &data)
 
self_toperator+= (const T &x)
 
template<class C >
void addAll (const C &c)
 
void remove (const T &key)
 
template<class C >
void removeAll (const C &c)
 
self_toperator-= (const T &x)
 
void remove (const Iter &i)
 
void copy (const HashTable< T, H > &t)
 
self_toperator= (const HashTable< T, H > &c)
 
T * get (const T &key)
 
- Public Member Functions inherited from HashKey< T >
t::hash computeHash (const T &key) const
 
bool isEqual (const T &key1, const T &key2) const
 
- Public Member Functions inherited from DefaultAllocatorDelegate
t::ptr allocate (t::size size) const
 
void free (t::ptr p) const
 
template<class T >
T * alloc () const
 

Protected Member Functions

node_t * find (const T &key) const
 
node_t * find_const (const T &key) const
 

Additional Inherited Members

- Static Public Member Functions inherited from HashKey< T >
static t::hash hash (const T &key)
 
static bool equals (const T &key1, const T &key2)
 

Detailed Description

template<class T, class H = HashKey<T>, class A = DefaultAlloc>
class elm::HashTable< T, H, A >

This class provides an hashing table implementation as an array of linked list. A small caching feature put to the head of the linked list last accessed items.

This class is the basic implementation of hash table. To use it as a map, refer to HashMap. To use it as a set, refer to HashSet.

Parameters
TType of stored data.
AAdapter to access key information (must implement concept::Adapter).
MManager of the hash table providing hashing and allocation services.
Deprecated:
Use HashMap instead.

Member Typedef Documentation

◆ self_t

typedef HashTable<T, H, A> self_t

Constructor & Destructor Documentation

◆ HashTable() [1/2]

HashTable ( int  size = 211)
inline

Build an hash table with the given size. Improved efficiency is obtained with prime number as sizes.

Parameters
sizeTable size (default to 211).

References fast< T >::clear().

◆ HashTable() [2/2]

HashTable ( const self_t h)
inline

◆ ~HashTable()

~HashTable ( void  )
inline

Member Function Documentation

◆ add()

◆ addAll()

void addAll ( const C &  c)
inline

◆ allocator() [1/2]

A& allocator ( )
inline

◆ allocator() [2/2]

const A& allocator ( ) const
inline

◆ begin()

Iter begin ( void  ) const
inline

◆ clear()

◆ contains()

bool contains ( const T &  x) const
inline

◆ contains_const()

bool contains_const ( const T &  x) const
inline

◆ containsAll()

bool containsAll ( const CC &  c) const
inline

◆ containsAll_const()

bool containsAll_const ( const CC &  c) const
inline

◆ copy()

◆ count()

int count ( void  ) const
inline

Count the number of items in the table.

Returns
Count of items.

Referenced by HashMap< K, T, H, A, E >::count(), and HashSet< T, H, A >::count().

◆ end()

Iter end ( void  ) const
inline

◆ equals()

◆ equals_const()

bool equals_const ( const HashTable< T > &  h) const
inline

◆ exists()

bool exists ( const T &  key) const
inline

◆ exists_const()

bool exists_const ( const T &  key) const
inline

◆ find()

node_t* find ( const T &  key) const
inlineprotected

◆ find_const()

node_t* find_const ( const T &  key) const
inlineprotected

◆ get() [1/2]

T* get ( const T &  key)
inline

◆ get() [2/2]

◆ get_const()

const T* get_const ( const T &  key) const
inline

◆ hash() [1/2]

H& hash ( )
inline

◆ hash() [2/2]

const H& hash ( ) const
inline

◆ hasKey()

bool hasKey ( const T &  key) const
inline

Test if a key is in the table.

Parameters
keyTested key.
Returns
True if there is an item in the table with the given key, false else.

References HashTable< T, H, A >::find().

Referenced by HashSet< T, H, A >::contains(), HashTable< T, H, A >::exists(), and HashMap< K, T, H, A, E >::hasKey().

◆ hasKey_const()

bool hasKey_const ( const T &  key) const
inline

◆ isEmpty()

bool isEmpty ( void  ) const
inline

HashTable::HashTable(const self_t& h); Clone constructor.

Parameters
hHash table to clone.

Test if the table is empty.

Returns
True if the table is empty, false else.

Referenced by HashMap< K, T, H, A, E >::isEmpty(), HashSet< T, H, A >::isEmpty(), and HashTable< T, H, A >::operator bool().

◆ operator bool()

operator bool ( ) const
inline

◆ operator!=()

bool operator!= ( const HashTable< T > &  t) const
inline

◆ operator+=()

self_t& operator+= ( const T &  x)
inline

◆ operator-=()

self_t& operator-= ( const T &  x)
inline

◆ operator=()

self_t& operator= ( const HashTable< T, H > &  c)
inline

◆ operator==()

bool operator== ( const HashTable< T > &  t) const
inline

◆ put()

void put ( const T &  data)
inline

Add a data in the table ensuring there is only one data with the corresponding key.

Parameters
dataAdded data.

References HashTable< T, H, A >::add(), and HashTable< T, H, A >::find().

Referenced by HashSet< T, H, A >::insert(), HashMap< K, T, H, A, E >::put(), and HashTable< T, H, A >::putAll().

◆ putAll()

void putAll ( const CC &  c)
inline

Add the items of the given table to the current one.

Parameters
mAdded table.

References HashTable< T, H, A >::put().

Referenced by HashTable< T, H, A >::HashTable(), and HashTable< T, H, A >::copy().

◆ remove() [1/2]

void remove ( const Iter i)
inline

References elm::io::p().

◆ remove() [2/2]

◆ removeAll()

void removeAll ( const C &  c)
inline

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