FreeFOAM The Cross-Platform CFD Toolkit
HashTable< T, Key, Hash > Class Template Reference

An STL-conforming hash table. More...

#include <OpenFOAM/HashTable.H>


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 84 of file HashTable.H.

+ 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 Treference
 Type that can be used for storing into HashTable::value_type.
typedef const Tconst_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.
List< Key > sortedToc () const
 Return the table of contents as a sorted list.
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 , class AnyHash >
label erase (const HashTable< AnyType, Key, AnyHash > &)
 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.
Toperator[] (const Key &)
 Find and return an hashedEntry.
const Toperator[] (const Key &) const
 Find and return an hashedEntry.
Toperator() (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 > &)

Member Typedef Documentation

typedef T value_type

Type of values the HashTable contains.

Definition at line 276 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 280 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 285 of file HashTable.H.

typedef label size_type

The type that can represent the size of a HashTable.

Definition at line 288 of file HashTable.H.


Constructor & Destructor Documentation

HashTable ( const label  size = 128)

Construct given initial table size.

Definition at line 62 of file HashTable.C.

HashTable ( Istream is,
const label  size = 128 
)

Construct from Istream.

Definition at line 33 of file HashTableIO.C.

References HashTable< T, Key, Hash >::operator>>.

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

Construct by transferring the parameter contents.

Definition at line 111 of file HashTable.C.

~HashTable ( )

Definition at line 129 of file HashTable.C.

References clear().


Member Function Documentation

bool empty ( ) const
inline

Return true if the hash table is empty.

Definition at line 65 of file HashTableI.H.

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

Find and return an iterator set at the hashedEntry.

If not found iterator = end()

Definition at line 172 of file HashTable.C.

References Foam::Info.

Referenced by dictionary::add(), cellTable::addCellZones(), faceZoneSet::addSet(), extendedCellToFaceStencil::calcDistributeMap(), enrichedPatch::calcEnrichedFaces(), cellMatcher::calcLocalFaces(), dictionary::changeKeyword(), primitiveMesh::checkFaceFaces(), objectRegistry::checkOut(), cyclicPolyPatch::coupledEdges(), autoSnapDriver::createZoneBaffles(), meshRefinement::decomposeCombineRegions(), faceZoneSet::deleteSet(), polyMeshAdder::findSharedPoints(), combineFaces::getMergeSets(), autoSnapDriver::getZoneSurfacePoints(), fvMeshSubset::interpolate(), cellModeller::lookup(), DictionaryBase< IDLListType, T >::lookup(), dictionary::lookupEntryPtr(), DictionaryBase< IDLListType, T >::lookupPtr(), dictionary::merge(), polyMeshAdder::mergePoints(), attachDetach::modifyMotionPoints(), slidingInterface::modifyMotionPoints(), polyBoundaryMesh::neighbourEdges(), HashTable< T, Key, Hash >::operator()(), HashTable< T, Key, Hash >::operator==(), HashTable< T, Key, Hash >::operator[](), OBJsurfaceFormat< Face >::read(), NASsurfaceFormat< Face >::read(), STARCDsurfaceFormat< Face >::read(), STARCD::readBoundary(), Foam::ReadFields(), DictionaryBase< IDLListType, T >::remove(), dictionary::remove(), undoableMeshCutter::removeSplitFaces(), genericPointPatchField< Type >::rmap(), duplicatePoints::setRefinement(), boundaryCutter::setRefinement(), undoableMeshCutter::setRefinement(), combineFaces::setUnrefinement(), UnsortedMeshedSurface< Face >::sortedZones(), faceZoneSet::subset(), syncTools::syncEdgeMap(), hexRef8::updateMesh(), meshReader::warnDuplicates(), cellZone::whichCell(), faceZone::whichFace(), pointZone::whichPoint(), PrimitivePatch< Face, FaceList, PointField, PointType >::whichPoint(), and ZoneMesh< ZoneType, MeshType >::whichZone().

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

Find and return an const_iterator set at the hashedEntry.

If not found iterator = end()

Definition at line 204 of file HashTable.C.

References Foam::Info.

Foam::List< Key > sortedToc ( ) const

Return the table of contents as a sorted list.

Definition at line 250 of file HashTable.C.

References Foam::sort().

Foam::Ostream & printInfo ( Ostream os) const

Print information.

Definition at line 55 of file HashTableIO.C.

References Foam::endl().

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

Assign a new hashedEntry, overwriting existing entries.

Definition at line 84 of file HashTableI.H.

bool erase ( const iterator cit)

Erase an hashedEntry specified by given iterator.

Definition at line 345 of file HashTable.C.

References Foam::Info.

Referenced by objectRegistry::checkOut(), polyBoundaryMesh::neighbourEdges(), Foam::ReadFields(), and HashPtrTable< T, Key, Hash >::remove().

bool erase ( const Key &  key)

Erase an hashedEntry specified by given key if in table.

Definition at line 428 of file HashTable.C.

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

Remove entries given by the listed keys from this HashTable.

Return the number of elements removed

Definition at line 444 of file HashTable.C.

References forAll.

Foam::label erase ( const HashTable< AnyType, Key, AnyHash > &  rhs)

Remove entries given by the given keys from this HashTable.

Return the number of elements removed. The parameter HashTable needs the same type of key, but the type of values held and the hashing function are arbitrary.

Definition at line 467 of file HashTable.C.

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

void resize ( const label  newSize)

Resize the hash table for efficiency.

Definition at line 488 of file HashTable.C.

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

Referenced by primitiveMesh::checkEdgeAlignment(), and removePoints::setRefinement().

void clearStorage ( )

Clear the table entries and the table itself.

Equivalent to clear() followed by resize(0)

Definition at line 549 of file HashTable.C.

References clear().

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

Transfer the contents of the argument table into this table.

and annull the argument table.

Definition at line 557 of file HashTable.C.

References clear().

Referenced by primitiveMesh::checkEdgeLength().

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

Transfer contents to the Xfer container.

Reimplemented in surfMesh.

Definition at line 95 of file HashTableI.H.

References Foam::xferMove().

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

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

Definition at line 138 of file HashTableI.H.

References HashTable< T, Key, Hash >::end(), HashTable< T, Key, Hash >::find(), HashTable< T, Key, Hash >::insert(), and Foam::T().

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

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 615 of file HashTable.C.

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

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

The opposite of the equality operation. Takes linear time.

Definition at line 646 of file HashTable.C.

References Foam::operator==().

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

iterator set to the begining of the HashTable

Reimplemented in Cloud< ParticleType >, Cloud< BasicReactingMultiphaseParcel< ThermoType > >, Cloud< basicThermoParcel >, Cloud< indexedParticle >, Cloud< trackedParticle >, Cloud< ParcelType >, Cloud< parcel >, Cloud< basicKinematicParcel >, Cloud< solidParticle >, Cloud< CoalParcel< ThermoType > >, Cloud< molecule >, Cloud< passiveParticle >, Cloud< dsmcParcel >, and Cloud< BasicReactingParcel< ThermoType > >.

Definition at line 310 of file HashTableI.H.

References Foam::Info, and HashTable< T, Key, Hash >::iterator.

Referenced by genericFvPatchField< Type >::autoMap(), genericPointPatchField< Type >::autoMap(), cellMatcher::calcLocalFaces(), edgeSurface::edgeSurface(), genericPointPatchField< Type >::genericPointPatchField(), surfaceSets::getHangingCells(), Foam::kShellIntegration(), Foam::mapClouds(), Foam::MapConsistentVolFields(), Foam::MapGeometricFields(), fvMeshAdder::MapSurfaceFields(), Foam::MapVolFields(), fvMeshAdder::MapVolFields(), surfaceFeatures::nearestSamples(), fvMeshDistribute::printFieldInfo(), argList::printUsage(), genericFvPatchField< Type >::rmap(), genericPointPatchField< Type >::rmap(), refinementIterator::setRefinement(), faceCollapser::setRefinement(), meshCutAndRemove::setRefinement(), meshCutter::setRefinement(), topoSet::subset(), triSurfaceTools::triangulate(), triSurfaceTools::triangulateFaceCentre(), Foam::UnMapped(), edgeVertex::updateLabels(), meshCutAndRemove::updateMesh(), meshCutter::updateMesh(), gnuplotGraph::write(), jplotGraph::write(), and xmgrGraph::write().

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

iterator set to beyond the end of the HashTable

Reimplemented in Cloud< ParticleType >, Cloud< BasicReactingMultiphaseParcel< ThermoType > >, Cloud< basicThermoParcel >, Cloud< indexedParticle >, Cloud< trackedParticle >, Cloud< ParcelType >, Cloud< parcel >, Cloud< basicKinematicParcel >, Cloud< solidParticle >, Cloud< CoalParcel< ThermoType > >, Cloud< molecule >, Cloud< passiveParticle >, Cloud< dsmcParcel >, and Cloud< BasicReactingParcel< ThermoType > >.

Definition at line 344 of file HashTableI.H.

Referenced by dictionary::add(), cellTable::addCellZones(), enrichedPatch::calcEnrichedFaces(), dictionary::changeKeyword(), primitiveMesh::checkFaceFaces(), autoSnapDriver::createZoneBaffles(), meshRefinement::decomposeCombineRegions(), edgeSurface::edgeSurface(), genericPointPatchField< Type >::genericPointPatchField(), surfaceSets::getHangingCells(), autoSnapDriver::getZoneSurfacePoints(), cellModeller::lookup(), DictionaryBase< IDLListType, T >::lookup(), dictionary::lookupEntryPtr(), DictionaryBase< IDLListType, T >::lookupPtr(), Foam::mapClouds(), Foam::MapConsistentVolFields(), Foam::MapGeometricFields(), fvMeshAdder::MapSurfaceFields(), Foam::MapVolFields(), fvMeshAdder::MapVolFields(), dictionary::merge(), polyMeshAdder::mergePoints(), slidingInterface::modifyMotionPoints(), polyBoundaryMesh::neighbourEdges(), HashTable< T, Key, Hash >::operator()(), HashTable< T, Key, Hash >::operator[](), fvMeshDistribute::printFieldInfo(), OBJsurfaceFormat< Face >::read(), NASsurfaceFormat< Face >::read(), STARCDsurfaceFormat< Face >::read(), Foam::ReadFields(), DictionaryBase< IDLListType, T >::remove(), dictionary::remove(), duplicatePoints::setRefinement(), meshCutAndRemove::setRefinement(), meshCutter::setRefinement(), UnsortedMeshedSurface< Face >::sortedZones(), topoSet::subset(), triSurfaceTools::triangulate(), triSurfaceTools::triangulateFaceCentre(), Foam::UnMapped(), edgeVertex::updateLabels(), meshReader::warnDuplicates(), cellZone::whichCell(), faceZone::whichFace(), pointZone::whichPoint(), ZoneMesh< ZoneType, MeshType >::whichZone(), gnuplotGraph::write(), jplotGraph::write(), and xmgrGraph::write().


Friends And Related Function Documentation

friend class HashPtrTable
friend

Declare friendship with the HashPtrTable class.

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