Classes | Public Types | Public Member Functions | Friends | List of all members
StaticHashTable< T, Key, Hash > Class Template Reference

STL conforming hash table. More...

Inheritance diagram for StaticHashTable< T, Key, Hash >:
Inheritance graph
[legend]
Collaboration diagram for StaticHashTable< T, Key, Hash >:
Collaboration graph
[legend]

Classes

class  Iterator
 An STL iterator. More...
 

Public Types

typedef Iterator< T &, StaticHashTable< T, Key, Hash > & > iterator
 
typedef Iterator< const T &, const StaticHashTable< T, Key, Hash > & > const_iterator
 
typedef T value_type
 Type of values the StaticHashTable contains. More...
 
typedef Treference
 Type that can be used for storing into StaticHashTable::value_type. More...
 
typedef const Tconst_reference
 Type that can be used for storing into constant. More...
 
typedef label size_type
 The type that can represent the size of a StaticHashTable. More...
 

Public Member Functions

 StaticHashTable (const label size=128)
 Construct given initial table size. More...
 
 StaticHashTable (Istream &, const label size=128)
 Construct from Istream. More...
 
 StaticHashTable (const StaticHashTable< T, Key, Hash > &)
 Construct as copy. More...
 
 StaticHashTable (const Xfer< StaticHashTable< T, Key, Hash > > &)
 Construct by transferring the parameter contents. More...
 
 ~StaticHashTable ()
 Destructor. More...
 
label size () const
 Return number of elements in table. More...
 
bool empty () const
 Return true if the hash table is empty. More...
 
bool found (const Key &key) const
 Return true if hashed entry is found in table. More...
 
iterator find (const Key &key)
 Find and return an iterator set at the hashed entry. More...
 
const_iterator find (const Key &key) const
 Find and return an const_iterator set at the hashed entry. More...
 
List< Key > toc () const
 Return the table of contents. More...
 
OstreamprintInfo (Ostream &) const
 Print information. More...
 
bool insert (const Key &key, const T &newElmt)
 Insert a new hashed entry. More...
 
bool set (const Key &, const T &newElmt)
 Assign a new hashed entry, overwriting existing entries. More...
 
bool erase (const iterator &it)
 Erase an hashed entry specified by given iterator. More...
 
bool erase (const Key &key)
 Erase an hashed entry specified by given key if in table. More...
 
void resize (const label newSize)
 Resize the hash table for efficiency. More...
 
label erase (const StaticHashTable< T, Key, Hash > &)
 Remove entries in the given hash table from this hash table. More...
 
void clear ()
 Clear all entries from table. More...
 
void clearStorage ()
 Clear the table entries and the table itself. More...
 
void transfer (StaticHashTable< T, Key, Hash > &)
 Transfer the contents of the argument table into this table. More...
 
Xfer< StaticHashTable< T, Key, Hash > > xfer ()
 Transfer contents to the Xfer container. More...
 
Toperator[] (const Key &)
 Find and return an hashed entry. More...
 
const Toperator[] (const Key &) const
 Find and return an hashed entry. More...
 
Toperator() (const Key &)
 Find and return an hashed entry, create it null if not present. More...
 
void operator= (const StaticHashTable< T, Key, Hash > &)
 Assignment. More...
 
bool operator== (const StaticHashTable< T, Key, Hash > &) const
 Equality. Two hash tables are equal if all contents of first are. More...
 
bool operator!= (const StaticHashTable< T, Key, Hash > &) const
 The opposite of the equality operation. More...
 
iterator begin ()
 Iterator set to the beginning of the StaticHashTable. More...
 
const iteratorend ()
 Iterator set to beyond the end of the StaticHashTable. More...
 
const_iterator cbegin () const
 const_iterator set to the beginning of the StaticHashTable More...
 
const const_iteratorcend () const
 const_iterator set to beyond the end of the StaticHashTable More...
 
const_iterator begin () const
 const_iterator set to the beginning of the StaticHashTable More...
 
const const_iteratorend () const
 const_iterator set to beyond the end of the StaticHashTable More...
 
- Public Member Functions inherited from StaticHashTableCore
 StaticHashTableCore ()
 Construct null. More...
 
 ClassName ("StaticHashTable")
 Define template name and debug. More...
 

Friends

class Iterator< T &, StaticHashTable< T, Key, Hash > & >
 
class Iterator< const T &, const StaticHashTable< T, Key, Hash > & >
 
Istreamoperator>> (Istream &, StaticHashTable< T, Key, Hash > &)
 
Ostreamoperator (Ostream &, const StaticHashTable< T, Key, Hash > &)
 

Additional Inherited Members

- Static Public Member Functions inherited from StaticHashTableCore
static label canonicalSize (const label)
 Return a canonical (power-of-two) size. More...
 

Detailed Description

template<class T, class Key = word, class Hash = string::hash>
class Foam::StaticHashTable< T, Key, Hash >

STL conforming hash table.

Note
Uses straight lists as underlying type. Is slower to insert than the standard HashTable, but should be more memory efficient and faster to access.
Source files

Definition at line 58 of file StaticHashTable.H.

Member Typedef Documentation

typedef Iterator< T&, StaticHashTable<T, Key, Hash>& > iterator

Definition at line 138 of file StaticHashTable.H.

typedef Iterator< const T&, const StaticHashTable<T, Key, Hash>& > const_iterator

Definition at line 150 of file StaticHashTable.H.

typedef T value_type

Type of values the StaticHashTable contains.

Definition at line 276 of file StaticHashTable.H.

typedef T& reference

Type that can be used for storing into StaticHashTable::value_type.

objects. This type is usually List::value_type&.

Definition at line 280 of file StaticHashTable.H.

typedef const T& const_reference

Type that can be used for storing into constant.

StaticHashTable::value_type objects. This type is usually const StaticHashTable::value_type&.

Definition at line 285 of file StaticHashTable.H.

typedef label size_type

The type that can represent the size of a StaticHashTable.

Definition at line 288 of file StaticHashTable.H.

Constructor & Destructor Documentation

StaticHashTable ( const label  size = 128)

Construct given initial table size.

Definition at line 63 of file StaticHashTable.C.

References Foam::abort(), Foam::FatalError, and FatalErrorIn.

Referenced by StaticHashTable< T, Key, Hash >::StaticHashTable().

Here is the call graph for this function:

Here is the caller graph for this function:

StaticHashTable ( Istream is,
const label  size = 128 
)

Construct from Istream.

Definition at line 34 of file StaticHashTableIO.C.

References Foam::abort(), Foam::FatalError, FatalErrorIn, and Foam::operator>>().

Here is the call graph for this function:

StaticHashTable ( const StaticHashTable< T, Key, Hash > &  ht)

Construct as copy.

Definition at line 86 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::StaticHashTable().

Here is the call graph for this function:

StaticHashTable ( const Xfer< StaticHashTable< T, Key, Hash > > &  ht)

Construct by transferring the parameter contents.

Definition at line 101 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::transfer().

Here is the call graph for this function:

Destructor.

Definition at line 119 of file StaticHashTable.C.

Member Function Documentation

Foam::label size ( ) const
inline

Return number of elements in table.

Definition at line 45 of file StaticHashTableI.H.

Referenced by StaticHashTable< T, Key, Hash >::printInfo().

Here is the caller graph for this function:

bool empty ( ) const
inline

Return true if the hash table is empty.

Definition at line 52 of file StaticHashTableI.H.

References StaticHashTable< T, Key, Hash >::insert().

Here is the call graph for this function:

bool found ( const Key &  key) const

Return true if hashed entry is found in table.

Definition at line 126 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::find(), forAll, and Foam::Info.

Referenced by StaticHashTable< T, Key, Hash >::erase().

Here is the call graph for this function:

Here is the caller graph for this function:

Foam::StaticHashTable< T, Key, Hash >::iterator find ( const Key &  key)

Find and return an iterator set at the hashed entry.

If not found iterator = end()

Definition at line 157 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::end(), forAll, and Foam::Info.

Referenced by StaticHashTable< T, Key, Hash >::erase(), StaticHashTable< T, Key, Hash >::found(), and StaticHashTable< T, Key, Hash >::operator==().

Here is the call graph for this function:

Here is the caller graph for this function:

Foam::StaticHashTable< T, Key, Hash >::const_iterator find ( const Key &  key) const

Find and return an const_iterator set at the hashed entry.

If not found iterator = end()

Definition at line 190 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::cend(), forAll, and Foam::Info.

Here is the call graph for this function:

Foam::List< Key > toc ( ) const

Return the table of contents.

Definition at line 222 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::cbegin(), StaticHashTable< T, Key, Hash >::cend(), forAll, Foam::Info, List< T >::setSize(), List< T >::size(), and Foam::T().

Here is the call graph for this function:

Foam::Ostream & printInfo ( Ostream os) const
bool insert ( const Key &  key,
const T newElmt 
)
inline

Insert a new hashed entry.

Definition at line 60 of file StaticHashTableI.H.

Referenced by StaticHashTable< T, Key, Hash >::empty(), StaticHashTable< T, Key, Hash >::operator=(), StaticHashTable< T, Key, Hash >::printInfo(), and StaticHashTable< T, Key, Hash >::resize().

Here is the caller graph for this function:

bool set ( const Key &  key,
const T newElmt 
)
inline

Assign a new hashed entry, overwriting existing entries.

Definition at line 71 of file StaticHashTableI.H.

bool erase ( const iterator it)

Erase an hashed entry specified by given iterator.

Definition at line 296 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::end(), Foam::Info, List< T >::setSize(), and List< T >::size().

Referenced by StaticHashTable< T, Key, Hash >::erase().

Here is the call graph for this function:

Here is the caller graph for this function:

bool erase ( const Key &  key)

Erase an hashed entry specified by given key if in table.

Definition at line 352 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::end(), StaticHashTable< T, Key, Hash >::erase(), and StaticHashTable< T, Key, Hash >::find().

Here is the call graph for this function:

void resize ( const label  newSize)
Foam::label erase ( const StaticHashTable< T, Key, Hash > &  rhs)

Remove entries in the given hash table from this hash table.

Return the number of elements removed

Definition at line 369 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::begin(), StaticHashTable< T, Key, Hash >::end(), StaticHashTable< T, Key, Hash >::erase(), and StaticHashTable< T, Key, Hash >::found().

Here is the call graph for this function:

void clear ( )

Clear all entries from table.

Definition at line 433 of file StaticHashTable.C.

References forAll.

Referenced by StaticHashTable< T, Key, Hash >::clearStorage(), StaticHashTable< T, Key, Hash >::operator=(), StaticHashTable< T, Key, Hash >::printInfo(), and StaticHashTable< T, Key, Hash >::transfer().

Here is the caller graph for this function:

void clearStorage ( )

Clear the table entries and the table itself.

Equivalent to clear() followed by resize(1)

Definition at line 446 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::clear(), StaticHashTable< T, Key, Hash >::resize(), and StaticHashTable< T, Key, Hash >::transfer().

Here is the call graph for this function:

void transfer ( StaticHashTable< T, Key, Hash > &  ht)

Transfer the contents of the argument table into this table.

and annul the argument table.

Definition at line 455 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::clear().

Referenced by StaticHashTable< T, Key, Hash >::clearStorage(), StaticHashTable< T, Key, Hash >::resize(), and StaticHashTable< T, Key, Hash >::StaticHashTable().

Here is the call graph for this function:

Here is the caller graph for this function:

Foam::Xfer< Foam::StaticHashTable< T, Key, Hash > > xfer ( )
inline

Transfer contents to the Xfer container.

Definition at line 82 of file StaticHashTableI.H.

References Foam::xferMove().

Here is the call graph for this function:

T & operator[] ( const Key &  key)
inline

Find and return an hashed entry.

Definition at line 91 of file StaticHashTableI.H.

References Foam::exit(), Foam::FatalError, FatalErrorIn, and T.

Here is the call graph for this function:

const T & operator[] ( const Key &  key) const
inline

Find and return an hashed entry.

Definition at line 109 of file StaticHashTableI.H.

References Foam::exit(), Foam::FatalError, and FatalErrorIn.

Here is the call graph for this function:

T & operator() ( const Key &  key)
inline

Find and return an hashed entry, create it null if not present.

Definition at line 130 of file StaticHashTableI.H.

References insert(), and T.

Here is the call graph for this function:

void operator= ( const StaticHashTable< T, Key, Hash > &  rhs)
bool operator== ( const StaticHashTable< T, Key, Hash > &  rhs) const

Equality. Two hash tables are equal if all contents of first are.

also in second and vice versa.

Definition at line 523 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::cbegin(), StaticHashTable< T, Key, Hash >::cend(), and StaticHashTable< T, Key, Hash >::find().

Referenced by StaticHashTable< T, Key, Hash >::operator!=().

Here is the call graph for this function:

Here is the caller graph for this function:

bool operator!= ( const StaticHashTable< T, Key, Hash > &  rhs) const

The opposite of the equality operation.

Definition at line 545 of file StaticHashTable.C.

References StaticHashTable< T, Key, Hash >::operator==().

Here is the call graph for this function:

Foam::StaticHashTable< T, Key, Hash >::iterator begin ( )
inline

Iterator set to the beginning of the StaticHashTable.

Definition at line 341 of file StaticHashTableI.H.

References forAll, and Foam::Info.

Referenced by StaticHashTable< T, Key, Hash >::erase(), and StaticHashTable< T, Key, Hash >::printInfo().

Here is the caller graph for this function:

const Foam::StaticHashTable< T, Key, Hash >::iterator & end ( )
inline

Iterator set to beyond the end of the StaticHashTable.

Definition at line 365 of file StaticHashTableI.H.

Referenced by StaticHashTable< T, Key, Hash >::erase(), StaticHashTable< T, Key, Hash >::find(), and StaticHashTable< T, Key, Hash >::printInfo().

Here is the caller graph for this function:

Foam::StaticHashTable< T, Key, Hash >::const_iterator cbegin ( ) const
inline

const_iterator set to the beginning of the StaticHashTable

Definition at line 373 of file StaticHashTableI.H.

References forAll, and Foam::Info.

Referenced by StaticHashTable< T, Key, Hash >::operator=(), StaticHashTable< T, Key, Hash >::operator==(), StaticHashTable< T, Key, Hash >::resize(), and StaticHashTable< T, Key, Hash >::toc().

Here is the caller graph for this function:

const Foam::StaticHashTable< T, Key, Hash >::const_iterator & cend ( ) const
inline
Foam::StaticHashTable< T, Key, Hash >::const_iterator begin ( ) const
inline

const_iterator set to the beginning of the StaticHashTable

Definition at line 405 of file StaticHashTableI.H.

const Foam::StaticHashTable< T, Key, Hash >::const_iterator & end ( ) const
inline

const_iterator set to beyond the end of the StaticHashTable

Definition at line 413 of file StaticHashTableI.H.

Friends And Related Function Documentation

friend class Iterator< T &, StaticHashTable< T, Key, Hash > & >
friend

Definition at line 159 of file StaticHashTable.H.

friend class Iterator< const T &, const StaticHashTable< T, Key, Hash > & >
friend

Definition at line 165 of file StaticHashTable.H.

Istream& operator>> ( Istream ,
StaticHashTable< T, Key, Hash > &   
)
friend
Ostream& operator ( Ostream ,
const StaticHashTable< T, Key, Hash > &   
)
friend

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