HashTable< T, Key, Hash > Class Template Reference

An STL-conforming hash table. More...

Inherits HashTableCore.

Inherited by EdgeMap< Foam::FvWallInfoData >, EdgeMap< scalar >, HashPtrTable< curve >, HashPtrTable< Foam::Field >, HashPtrTable< Foam::Function1< scalar > >, HashPtrTable< Foam::GeometricField >, HashPtrTable< Foam::List >, HashPtrTable< Foam::OFstream >, HashPtrTable< Foam::sutherlandTransport >, HashPtrTable< Foam::unknownTypeFunction1 >, HashPtrTable< HashPtrTable< volScalarField >, phaseInterfaceKey, phaseInterfaceKey::hash >, HashPtrTable< IOobject >, HashPtrTable< surfaceScalarField, phaseInterfaceKey, phaseInterfaceKey::hash >, HashPtrTable< T, label, Hash< label > >, HashPtrTable< volScalarField, phaseInterfaceKey, phaseInterfaceKey::hash >, Map< dictionary >, Map< Foam::edge >, Map< Foam::FvWallInfoData >, Map< Foam::List >, Map< Foam::Pair< Foam::edge > >, Map< Foam::splitCell *>, Map< Foam::Vector >, and Map< label >.

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

Classes

class  const_iterator
 An STL-conforming const_iterator. More...
 
class  iterator
 An STL-conforming iterator. More...
 
class  iteratorBase
 The iterator base for HashTable. More...
 

Public Types

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

Public Member Functions

 HashTable (const label size=128)
 Construct given initial table size. More...
 
 HashTable (Istream &, const label size=128)
 Construct from Istream. More...
 
 HashTable (const HashTable< T, Key, Hash > &)
 Copy constructor. More...
 
 HashTable (HashTable< T, Key, Hash > &&)
 Move constructor. More...
 
 HashTable (std::initializer_list< Tuple2< Key, T >>)
 Construct from an initialiser list. More...
 
 ~HashTable ()
 Destructor. More...
 
label capacity () const
 The size of the underlying table. 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 &) const
 Return true if hashedEntry is found in table. More...
 
iterator find (const Key &)
 Find and return an iterator set at the hashedEntry. More...
 
const_iterator find (const Key &) const
 Find and return an const_iterator set at the hashedEntry. More...
 
List< Key > toc () const
 Return the table of contents. More...
 
List< Key > sortedToc () const
 Return the table of contents as a sorted list. More...
 
OstreamprintInfo (Ostream &) const
 Print information. More...
 
bool insert (const Key &, const T &newElmt)
 Insert a new hashedEntry. More...
 
bool set (const Key &, const T &newElmt)
 Assign a new hashedEntry, overwriting existing entries. More...
 
bool erase (const iterator &)
 Erase a hashedEntry specified by given iterator. More...
 
bool erase (const Key &)
 Erase a hashedEntry specified by the given key. More...
 
label erase (const UList< Key > &)
 Remove entries given by the listed keys from this HashTable. More...
 
template<class AnyType , class AnyHash >
label erase (const HashTable< AnyType, Key, AnyHash > &)
 Remove entries given by the given keys from this HashTable. More...
 
void resize (const label newSize)
 Resize the hash table for efficiency. More...
 
void clear ()
 Clear all entries from table. More...
 
void clearStorage ()
 Clear the table entries and the table itself. More...
 
void shrink ()
 Shrink the allocated table to approx. twice number of elements. More...
 
void transfer (HashTable< T, Key, Hash > &)
 Transfer the contents of the argument table into this table. More...
 
Toperator[] (const Key &)
 Find and return a hashedEntry. More...
 
const Toperator[] (const Key &) const
 Find and return a hashedEntry. More...
 
Toperator() (const Key &)
 Find and return a hashedEntry, create it null if not present. More...
 
void operator= (const HashTable< T, Key, Hash > &)
 Assignment operator. More...
 
void operator= (HashTable< T, Key, Hash > &&)
 Move assignment operator. More...
 
void operator= (std::initializer_list< Tuple2< Key, T >>)
 Assignment to an initialiser list. More...
 
bool operator== (const HashTable< T, Key, Hash > &) const
 Equality. Hash tables are equal if the keys and values are equal. More...
 
bool operator!= (const HashTable< T, Key, Hash > &) const
 The opposite of the equality operation. Takes linear time. More...
 
iterator begin ()
 Iterator set to the beginning of the HashTable. More...
 
const_iterator cbegin () const
 const_iterator set to the beginning of the HashTable More...
 
const_iterator begin () const
 const_iterator set to the beginning of the HashTable More...
 
template<class AnyType , class AnyHash >
Foam::label erase (const HashTable< AnyType, Key, AnyHash > &rhs)
 
- Public Member Functions inherited from HashTableCore
 HashTableCore ()
 Construct null. More...
 
 ClassName ("HashTable")
 Define template name and debug. More...
 

Friends

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

Additional Inherited Members

- Static Public Member Functions inherited from HashTableCore
static label canonicalSize (const label)
 Return a canonical (power-of-two) size. More...
 
static iteratorEnd cend ()
 iteratorEnd set to beyond the end of any HashTable More...
 
static iteratorEnd end ()
 iteratorEnd set to beyond the end of any HashTable More...
 
- Static Public Attributes inherited from HashTableCore
static const label maxTableSize
 Maximum allowable table size. More...
 

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

Member Typedef Documentation

◆ value_type

typedef T value_type

Type of values the HashTable contains.

Definition at line 332 of file HashTable.H.

◆ reference

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

◆ const_reference

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

◆ size_type

typedef label size_type

The type that can represent the size of a HashTable.

Definition at line 344 of file HashTable.H.

Constructor & Destructor Documentation

◆ HashTable() [1/5]

HashTable ( const label  size = 128)

Construct given initial table size.

Definition at line 36 of file HashTable.C.

Referenced by HashTable< Foam::phase *>::HashTable().

Here is the caller graph for this function:

◆ HashTable() [2/5]

HashTable ( Istream is,
const label  size = 128 
)

Construct from Istream.

Definition at line 33 of file HashTableIO.C.

◆ HashTable() [3/5]

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

Copy constructor.

Definition at line 56 of file HashTable.C.

◆ HashTable() [4/5]

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

Move constructor.

Definition at line 69 of file HashTable.C.

◆ HashTable() [5/5]

HashTable ( std::initializer_list< Tuple2< Key, T >>  lst)

Construct from an initialiser list.

Definition at line 84 of file HashTable.C.

◆ ~HashTable()

~HashTable ( )

Destructor.

Definition at line 100 of file HashTable.C.

Member Function Documentation

◆ capacity()

Foam::label capacity ( ) const
inline

The size of the underlying table.

Definition at line 58 of file HashTableI.H.

◆ size()

Foam::label size ( ) const
inline

Return number of elements in table.

Definition at line 65 of file HashTableI.H.

Referenced by singleProcessorFaceSetsConstraint::add(), cellTable::addCellZones(), snappyLayerDriver::addLayers(), polyTopoChange::addMesh(), cellToFaceStencil::calcFaceStencil(), pointMVCWeight::calcWeights(), primitiveMesh::cellEdges(), primitiveMesh::cellPoints(), primitiveMesh::checkEdgeLength(), motionSmootherAlgo::checkMesh(), edgeCollapser::checkMeshQuality(), hexRef8::consistentSlowRefinement2(), meshRefinement::dupNonManifoldPoints(), surfaceSets::getHangingCells(), combineFaces::getMergeSets(), removePoints::getUnrefimentSet(), IOobjectList::lookup(), IOobjectList::lookupClass(), meshToMesh::mapAndOpTgtToSrc(), polyBoundaryMesh::matchGroups(), meshRefinement::mergePatchFacesUndo(), NamedEnum< compressibleField, 8 >::names(), IOobjectList::names(), polyBoundaryMesh::nbrEdges(), distribution::normalised(), minEqOpFace::operator()(), HashTable< Foam::phase *>::operator==(), Foam::polyMeshZipUpCells(), fvMeshDistribute::printCoupleInfo(), fvMeshDistribute::printFieldInfo(), distribution::raw(), repatchMesh::readTriSurface(), structuredRenumber::renumber(), faceAreaWeightAMI::restartUncoveredSourceFace(), motionSmootherAlgo::scaleMesh(), polyTopoChange::setCapacity(), fvMeshSubset::setCellSubset(), duplicatePoints::setRefinement(), removePoints::setRefinement(), meshCutAndRemove::setRefinement(), meshCutter::setRefinement(), hexRef8::setUnrefinement(), UnsortedMeshedSurface< Face >::sortedZones(), faceZoneSet::sync(), boundaryCutter::topoChange(), localPointRegion::topoChange(), meshCutAndRemove::topoChange(), meshCutter::topoChange(), triSurfaceRegionSearch::treeByRegion(), loadBalancer::update(), edgeVertex::updateLabels(), domainDecomposition::writeComplete(), domainDecomposition::writeProcs(), and graph::y().

◆ empty()

bool empty ( ) const
inline

Return true if the hash table is empty.

Definition at line 72 of file HashTableI.H.

Referenced by forces::calcForcesMoment(), and globalIndexAndTransform::transformIndicesForPatches().

Here is the caller graph for this function:

◆ found()

bool found ( const Key &  key) const

Return true if hashedEntry is found in table.

Definition at line 113 of file HashTable.C.

Referenced by fieldAverage::addMeanFieldType(), fieldAverage::addPrime2MeanFieldType(), faceZoneToFaceZone::applyToSet(), setToPointZone::applyToSet(), setToCellZone::applyToSet(), setToFaceZone::applyToSet(), setAndNormalToFaceZone::applyToSet(), setsToFaceZone::applyToSet(), addPatchCellLayer::calcSidePatch(), layerAdditionRemoval::changeTopology(), edgeCollapser::checkMeshQuality(), edgeMeshFormatsCore::checkSupport(), surfaceFormatsCore::checkSupport(), motionSmootherAlgo::correctBoundaryConditions(), geomCellLooper::cut(), HashTable< Foam::phase *>::erase(), scalarTransport::execute(), cellFeatures::faceMap(), polyMeshFilter::filter(), surfaceSets::getHangingCells(), removePoints::getUnrefimentSet(), fvMeshAdder::MapDimFields(), fvMeshAdder::MapPointFields(), fvMeshAdder::MapSurfaceFields(), fvMeshAdder::MapVolFields(), NamedEnum< compressibleField, 8 >::names(), UnsortedMeshedSurface< Face >::New(), MeshedSurface< Foam::face >::New(), cellCuts::nonAnchorPoints(), nonConformalBoundary::nonConformalNonCoupledPatchIDs(), ListPlusEqOp< T, Size >::operator()(), InflationInjection< CloudType >::parcelsToInject(), fvMeshDistribute::printFieldInfo(), STARCD::readBoundary(), STARCD::readCells(), faceAreaWeightAMI::restartUncoveredSourceFace(), fvMeshSubset::setCellSubset(), motionSmootherAlgo::setDisplacementPatchFields(), cellTable::setName(), boundaryCutter::setRefinement(), surfaceIntersection::surfaceIntersection(), UnsortedMeshedSurface< Face >::write(), MeshedSurface< Foam::face >::write(), regionSizeDistribution::write(), and domainDecomposition::writeProcs().

Here is the caller graph for this function:

◆ find() [1/2]

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

Referenced by distribution::add(), cellTable::addCellZones(), faceZoneSet::addSet(), enrichedPatch::calcEnrichedFaces(), cellMatcher::calcLocalFaces(), createShellMesh::calcPointRegions(), GAMGAgglomeration::calculateRegionMaster(), primitiveMesh::checkFaceFaces(), objectRegistry::checkIn(), objectRegistry::checkOut(), probes::classifyFields(), cyclicPolyPatch::coupledEdges(), cyclicAMIGAMGInterface::cyclicAMIGAMGInterface(), cyclicGAMGInterface::cyclicGAMGInterface(), faceZoneSet::deleteSet(), HashTable< Foam::phase *>::find(), HashTable< Foam::phase *>::found(), snappySnapDriver::getZoneSurfacePoints(), polyBoundaryMesh::groupPatchIDs(), Foam::stringOps::inplaceExpand(), distribution::insertMissingKeys(), fvMeshSubset::interpolate(), lduPrimitiveMesh::lduPrimitiveMesh(), zone::localID(), IOobjectList::lookup(), fvMeshAdder::MapSurfaceFields(), PatchTools::matchEdges(), PatchTools::matchPoints(), globalMeshData::mergePoints(), polyTopoChange::modifyFace(), attachDetach::modifyMotionPoints(), slidingInterface::modifyMotionPoints(), polyTopoChange::modifyPoint(), cellTable::name(), NamedEnum< compressibleField, 8 >::names(), polyBoundaryMesh::nbrEdges(), minEqOpFace::operator()(), Foam::parseNASCoord(), PatchTools::pointNormals(), fvMeshDistribute::printCoupleInfo(), processorGAMGInterface::processorGAMGInterface(), OBJsurfaceFormat< Face >::read(), NASsurfaceFormat< Face >::read(), STARCDsurfaceFormat< Face >::read(), STARCD::readBoundary(), cellTable::setName(), duplicatePoints::setRefinement(), edgeCollapser::setRefinement(), combineFaces::setUnrefinement(), UnsortedMeshedSurface< Face >::sortedZones(), faceZoneSet::subset(), surfaceFeatures::surfaceFeatures(), syncTools::syncEdgeList(), syncTools::syncEdgeMap(), syncTools::syncPointList(), hexRef8::topoChange(), vtkUnstructuredReader::vtkUnstructuredReader(), PrimitivePatch< IndirectList< face >, const pointField & >::whichPoint(), MeshZones< cellZone, polyMesh >::whichZone(), meshRefinement::zonify(), and TRIsurfaceFormatCore::~TRIsurfaceFormatCore().

◆ find() [2/2]

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

◆ toc()

◆ sortedToc()

◆ printInfo()

Foam::Ostream & printInfo ( Ostream os) const

Print information.

Definition at line 58 of file HashTableIO.C.

◆ insert()

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

Insert a new hashedEntry.

Definition at line 80 of file HashTableI.H.

Referenced by IOobjectList::add(), distribution::add(), polyTopoChange::addCell(), polyTopoChange::addFace(), polyTopoChange::addPoint(), boundaryRegion::append(), cellTable::append(), addPatchCellLayer::calcSidePatch(), primitiveMesh::checkFaceFaces(), objectRegistry::checkIn(), globalMeshData::coupledPatchMeshEdgeMap(), HashTable< Foam::phase *>::empty(), polyBoundaryMesh::groupPatchIDs(), HashSet< Foam::triFace, Foam::Hash< Foam::triFace > >::insert(), distribution::insertMissingKeys(), IOobjectList::IOobjectList(), IOobjectList::lookup(), objectRegistry::lookupClass(), IOobjectList::lookupClass(), polyTopoChange::modifyFace(), polyTopoChange::modifyPoint(), NamedEnum< compressibleField, 8 >::names(), polyBoundaryMesh::nbrEdges(), cellCuts::nonAnchorPoints(), minEqOpFace::operator()(), ListPlusEqOp< T, Size >::operator()(), ifEqEqOp< value >::operator()(), cellTable::operator=(), Foam::parseNASCoord(), pointMVCWeight::pointMVCWeight(), fvMeshDistribute::printCoupleInfo(), patchToPatch::rDistributeTgt(), OBJsurfaceFormat< Face >::read(), NASsurfaceFormat< Face >::read(), STARCDsurfaceFormat< Face >::read(), functionObjectList::read(), STARCD::readBoundary(), repatchMesh::readTriSurface(), HashTable< Foam::phase *>::resize(), fvMeshSubset::setCellSubset(), removePoints::setRefinement(), boundaryCutter::setRefinement(), combineFaces::setRefinement(), meshCutAndRemove::setRefinement(), meshCutter::setRefinement(), combineFaces::setUnrefinement(), UnsortedMeshedSurface< Face >::sortedZones(), hexRef8::storeData(), meshToMesh::update(), meshReader::warnDuplicates(), domainDecomposition::writeComplete(), meshRefinement::zonify(), and TRIsurfaceFormatCore::~TRIsurfaceFormatCore().

◆ set()

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

Assign a new hashedEntry, overwriting existing entries.

Definition at line 91 of file HashTableI.H.

Referenced by domainDecomposition::procFaceAddressingBf(), and refinementRegions::refinementRegions().

Here is the caller graph for this function:

◆ erase() [1/5]

◆ erase() [2/5]

bool erase ( const Key &  key)

Erase a hashedEntry specified by the given key.

Definition at line 383 of file HashTable.C.

◆ erase() [3/5]

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

◆ erase() [4/5]

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

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.

◆ resize()

void resize ( const label  newSize)

◆ clear()

◆ clearStorage()

void clearStorage ( )

Clear the table entries and the table itself.

Equivalent to clear() followed by resize(0)

Definition at line 492 of file HashTable.C.

Referenced by polyTopoChange::changeMesh(), polyTopoChange::clear(), and polyTopoChange::makeMesh().

Here is the caller graph for this function:

◆ shrink()

void shrink ( )

Shrink the allocated table to approx. twice number of elements.

Definition at line 500 of file HashTable.C.

◆ transfer()

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

Transfer the contents of the argument table into this table.

and annul the argument table.

Definition at line 513 of file HashTable.C.

Referenced by primitiveMesh::checkEdgeLength(), polyBoundaryMesh::matchGroups(), boundaryCutter::topoChange(), localPointRegion::topoChange(), meshCutAndRemove::topoChange(), and meshCutter::topoChange().

Here is the caller graph for this function:

◆ operator[]() [1/2]

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

Find and return a hashedEntry.

Definition at line 103 of file HashTableI.H.

Referenced by boundaryRegion::boundaryType(), cellTable::combine(), and boundaryRegion::rename().

Here is the caller graph for this function:

◆ operator[]() [2/2]

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

Find and return a hashedEntry.

Definition at line 120 of file HashTableI.H.

◆ operator()()

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

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

Definition at line 137 of file HashTableI.H.

◆ operator=() [1/3]

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

Assignment operator.

Definition at line 537 of file HashTable.C.

◆ operator=() [2/3]

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

Move assignment operator.

Definition at line 568 of file HashTable.C.

◆ operator=() [3/3]

void operator= ( std::initializer_list< Tuple2< Key, T >>  lst)

Assignment to an initialiser list.

Definition at line 586 of file HashTable.C.

◆ operator==()

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

Equality. Hash tables are equal if the keys and values are equal.

Independent of table storage size and table order.

Definition at line 609 of file HashTable.C.

◆ operator!=()

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

The opposite of the equality operation. Takes linear time.

Definition at line 635 of file HashTable.C.

◆ begin() [1/2]

◆ cbegin()

◆ begin() [2/2]

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

const_iterator set to the beginning of the HashTable

Definition at line 514 of file HashTableI.H.

◆ erase() [5/5]

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

Definition at line 411 of file HashTable.C.

Friends And Related Function Documentation

◆ HashPtrTable

friend class HashPtrTable
friend

Declare friendship with the HashPtrTable class.

Definition at line 184 of file HashTable.H.

◆ iteratorBase

friend class iteratorBase
friend

Declare friendship with the iteratorBase.

Definition at line 191 of file HashTable.H.

◆ iterator

friend class iterator
friend

Declare friendship with the iterator.

Definition at line 194 of file HashTable.H.

◆ const_iterator

friend class const_iterator
friend

Declare friendship with the const_iterator.

Definition at line 197 of file HashTable.H.

◆ operator>>

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

◆ operator

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

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