FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

StaticHashTable< T, Key, Hash > Class Template Reference

STL conforming hash table. More...

#include <OpenFOAM/StaticHashTable.H>


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 86 of file StaticHashTable.H.

Collaboration diagram for StaticHashTable< T, Key, Hash >:

List of all members.

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.
typedef T &  reference
 Type that can be used for storing into StaticHashTable::value_type.
typedef const T &  const_reference
 Type that can be used for storing into constant.
typedef label  size_type
 The type that can represent the size of a StaticHashTable.

Public Member Functions

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

Friends

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

Member Typedef Documentation

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

Definition at line 117 of file StaticHashTable.H.

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

Definition at line 129 of file StaticHashTable.H.

typedef T value_type

Type of values the StaticHashTable contains.

Definition at line 254 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 258 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 263 of file StaticHashTable.H.

typedef label size_type

The type that can represent the size of a StaticHashTable.

Definition at line 266 of file StaticHashTable.H.


Constructor & Destructor Documentation

StaticHashTable ( const label   size = 128  )

Construct given initial table size.

Definition at line 64 of file StaticHashTable.C.

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

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 operator>>().

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

Construct as copy.

Definition at line 87 of file StaticHashTable.C.

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

Construct by transferring the parameter contents.

Definition at line 103 of file StaticHashTable.C.

Definition at line 121 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.

bool empty (  ) const [inline]

Return true if the hash table is empty.

Definition at line 52 of file StaticHashTableI.H.

bool found ( const Key &   key  ) const

Return true if hashed entry is found in table.

Definition at line 128 of file StaticHashTable.C.

References forAll, and Foam::Info.

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

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 159 of file StaticHashTable.C.

References forAll, and Foam::Info.

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

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 192 of file StaticHashTable.C.

References forAll, and Foam::Info.

Foam::List< Key > toc (  ) const

Return the table of contents.

Definition at line 224 of file StaticHashTable.C.

Foam::Ostream & printInfo ( Ostream &   os  ) const

Print information.

Definition at line 63 of file StaticHashTableIO.C.

References Foam::endl(), and forAll.

bool insert ( const Key &   key,
const T &   newElmt  
) [inline]

Insert a new hashed entry.

Definition at line 60 of file StaticHashTableI.H.

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

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 298 of file StaticHashTable.C.

References Foam::Info, List< T >::setSize(), and List< T >::size().

bool erase ( const Key &   key  )

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

Definition at line 369 of file StaticHashTable.C.

void resize ( const label   newSize  )

Resize the hash table for efficiency.

Definition at line 407 of file StaticHashTable.C.

References Foam::abort(), Foam::FatalError, FatalErrorIn, Foam::Info, and StaticHashTable< T, Key, Hash >::insert().

Referenced by Foam::operator>>().

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 386 of file StaticHashTable.C.

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

void clear (  )

Clear all entries from table.

Definition at line 450 of file StaticHashTable.C.

References forAll.

Referenced by Foam::operator>>().

void clearStorage (  )

Clear the table entries and the table itself.

Equivalent to clear() followed by resize(1)

Definition at line 463 of file StaticHashTable.C.

References clear().

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

Transfer the contents of the argument table into this table.

and annull the argument table.

Definition at line 473 of file StaticHashTable.C.

References clear().

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().

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, and FatalErrorIn.

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.

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.

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 541 of file StaticHashTable.C.

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

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

The opposite of the equality operation.

Definition at line 572 of file StaticHashTable.C.

References Foam::operator==().

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

iterator set to the beginning of the StaticHashTable

Definition at line 336 of file StaticHashTableI.H.

References forAll, and Foam::Info.

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

iterator set to beyond the end of the StaticHashTable

Definition at line 360 of file StaticHashTableI.H.

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

const_iterator set to the beginning of the StaticHashTable

Definition at line 368 of file StaticHashTableI.H.

References forAll, and Foam::Info.

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

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

const_iterator set to beyond the end of the StaticHashTable

Definition at line 392 of file StaticHashTableI.H.

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

Foam::StaticHashTable< T, Key, Hash >::const_iterator begin (  ) const [inline]

const_iterator set to the beginning of the StaticHashTable

Definition at line 400 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 408 of file StaticHashTableI.H.


Friends And Related Function Documentation

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

Definition at line 138 of file StaticHashTable.H.

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

Definition at line 144 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: