OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

HashTable< T, Key, Hash > Class Template Reference

An STL-conforming hash table. More...

Inheritance diagram for HashTable< T, Key, Hash >:
Collaboration diagram for HashTable< T, Key, Hash >:

List of all members.


Classes

class  const_iterator
 An STL-conforming const_iterator. More...
struct  hashedEntry
class  iterator
 An STL-conforming iterator. More...

Public Types

typedef T value_type
 Type of values the HashTable contains.
typedef T & reference
 Type that can be used for storing into HashTable::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 HashTable.

Public Member Functions

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

Friends

class HashPtrTable
 Declare friendship with the HashPtrTable class.
class iterator
class const_iterator
Istreamoperator>> (Istream &, HashTable< T, Key, Hash > &)
Ostreamoperator (Ostream &, const HashTable< T, Key, Hash > &)

Detailed Description

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

An STL-conforming hash table.

Note:
Hashing index collisions are handled via chaining using a singly-linked list with the colliding entry being added to the head of the linked list. Thus copying the hash table (or indeed even resizing it) will often result in a different hash order. Use a sorted table-of-contents when the hash order is important.
Source files

Definition at line 79 of file HashTable.H.


Member Typedef Documentation

typedef T value_type

Type of values the HashTable contains.

Definition at line 284 of file HashTable.H.

typedef T& reference

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

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

Definition at line 290 of file HashTable.H.

typedef const T& const_reference

Type that can be used for storing into constant.

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

Definition at line 297 of file HashTable.H.

typedef label size_type

The type that can represent the size of a HashTable.

Definition at line 300 of file HashTable.H.


Constructor & Destructor Documentation

HashTable ( const label  size = 128  )  [inline]

Construct given initial table size.

Definition at line 54 of file HashTable.C.

HashTable ( Istream is,
const label  size = 128 
) [inline]

Construct from Istream.

Definition at line 25 of file HashTableIO.C.

HashTable ( const HashTable< T, Key, Hash > &  ht  )  [inline]

Construct as copy.

Definition at line 76 of file HashTable.C.

HashTable ( const Xfer< HashTable< T, Key, Hash > > &  ht  )  [inline]

Construct by transferring the parameter contents.

Definition at line 103 of file HashTable.C.

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

Here is the call graph for this function:

~HashTable (  )  [inline]

Definition at line 121 of file HashTable.C.


Member Function Documentation

bool empty (  )  const [inline]

Return true if the hash table is empty.

Definition at line 57 of file HashTableI.H.

bool found ( const Key &  key  )  const [inline]

Foam::HashTable< T, Key, Hash >::iterator find ( const Key &  key  )  [inline]

Find and return an iterator set at the hashedEntry.

If not found iterator = end()

Definition at line 164 of file HashTable.C.

Referenced by enrichedPatch::calcEnrichedFaces(), Foam::parseNASCoord(), STARCD::readBoundary(), and PrimitivePatch< Face, FaceList, PointField, PointType >::whichPoint().

Here is the caller graph for this function:

Foam::HashTable< T, Key, Hash >::const_iterator find ( const Key &  key  )  const [inline]

Find and return an const_iterator set at the hashedEntry.

If not found iterator = end()

Definition at line 196 of file HashTable.C.

Foam::List< Key > toc (  )  const [inline]

Return the table of contents.

Definition at line 227 of file HashTable.C.

Foam::Ostream & printInfo ( Ostream os  )  const [inline]

Print information.

Definition at line 47 of file HashTableIO.C.

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

Assign a new hashedEntry, overwriting existing entries.

Definition at line 76 of file HashTableI.H.

bool erase ( const iterator cit  )  [inline]

Erase an hashedEntry specified by given iterator.

Definition at line 327 of file HashTable.C.

bool erase ( const Key &  key  )  [inline]

Erase an hashedEntry specified by given key if in table.

Definition at line 410 of file HashTable.C.

Foam::label erase ( const UList< Key > &  keys  )  [inline]

Remove entries given by the listed keys from this HashTable.

Return the number of elements removed

Definition at line 426 of file HashTable.C.

Foam::label erase ( const HashTable< AnyType, Key, Hash > &  rhs  )  [inline]

Remove entries given by the given keys from this HashTable.

Return the number of elements removed. The parameter HashTable needs the same type of keys, but but the type of values held is arbitrary.

Definition at line 449 of file HashTable.C.

void resize ( const label  newSize  )  [inline]

Resize the hash table for efficiency.

Definition at line 473 of file HashTable.C.

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

Here is the caller graph for this function:

void clearStorage (  )  [inline]

Clear the table entries and the table itself.

Equivalent to clear() followed by resize(0)

Definition at line 534 of file HashTable.C.

void transfer ( HashTable< T, Key, Hash > &  ht  )  [inline]

Transfer the contents of the argument table into this table.

and annull the argument table.

Definition at line 542 of file HashTable.C.

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

Here is the call graph for this function:

Foam::Xfer< Foam::HashTable< T, Key, Hash > > xfer (  )  [inline]

Transfer contents to the Xfer container.

Reimplemented in surfMesh.

Definition at line 87 of file HashTableI.H.

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

Find and return an hashedEntry.

Definition at line 96 of file HashTableI.H.

References Foam::xferMove().

Here is the call graph for this function:

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

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

Definition at line 130 of file HashTableI.H.

void operator= ( const HashTable< T, Key, Hash > &  rhs  )  [inline]

Assignment.

Definition at line 566 of file HashTable.C.

bool operator== ( const HashTable< T, Key, Hash > &  rhs  )  const [inline]

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

also in second and vice versa. So does not depend on table size or order!

Definition at line 600 of file HashTable.C.

References insert().

Here is the call graph for this function:

bool operator!= ( const HashTable< T, Key, Hash > &  rhs  )  const [inline]

The opposite of the equality operation. Takes linear time.

Definition at line 631 of file HashTable.C.


Friends And Related Function Documentation

friend class HashPtrTable [friend]

Declare friendship with the HashPtrTable class.

Definition at line 141 of file HashTable.H.

Istream& operator>> ( Istream ,
HashTable< T, Key, Hash > &   
) [friend]

Ostream& operator ( Ostream ,
const HashTable< T, Key, Hash > &   
) [friend]

Referenced by argList::option().


The documentation for this class was generated from the following files:
Copyright © 2000-2009 OpenCFD Ltd