ListHashTable< T, Key, Hash > Class Template Reference

STL conforming hash table using contiguous lists rather than linked lists. More...

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

Classes

class  Iterator
 An STL iterator. More...
 

Public Types

typedef Iterator< T &, ListHashTable< T, Key, Hash > &> iterator
 
typedef Iterator< const T &, const ListHashTable< T, Key, Hash > &> const_iterator
 
typedef T value_type
 Type of values the ListHashTable contains. More...
 
typedef Treference
 Type that can be used for storing into ListHashTable::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 ListHashTable. More...
 

Public Member Functions

 ListHashTable (const label size=128)
 Construct given initial table size. More...
 
 ListHashTable (Istream &, const label size=128)
 Construct from Istream. More...
 
 ListHashTable (const ListHashTable< T, Key, Hash > &)
 Copy constructor. More...
 
 ListHashTable (ListHashTable< T, Key, Hash > &&)
 Move constructor. More...
 
 ~ListHashTable ()
 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 ListHashTable< 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 (ListHashTable< T, Key, Hash > &)
 Transfer the contents of the argument table into this table. 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 ListHashTable< T, Key, Hash > &)
 Assignment operator. More...
 
void operator= (ListHashTable< T, Key, Hash > &&)
 Move assignment operator. More...
 
bool operator== (const ListHashTable< T, Key, Hash > &) const
 Equality. Two hash tables are equal if all contents of first are. More...
 
bool operator!= (const ListHashTable< T, Key, Hash > &) const
 The opposite of the equality operation. More...
 
iterator begin ()
 Iterator set to the beginning of the ListHashTable. More...
 
const iteratorend ()
 Iterator set to beyond the end of the ListHashTable. More...
 
const_iterator cbegin () const
 const_iterator set to the beginning of the ListHashTable More...
 
const const_iteratorcend () const
 const_iterator set to beyond the end of the ListHashTable More...
 
const_iterator begin () const
 const_iterator set to the beginning of the ListHashTable More...
 
const const_iteratorend () const
 const_iterator set to beyond the end of the ListHashTable More...
 
- Public Member Functions inherited from ListHashTableCore
 ListHashTableCore ()
 Construct null. More...
 
 ClassName ("ListHashTable")
 Define template name and debug. More...
 

Friends

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

Additional Inherited Members

- Static Public Member Functions inherited from ListHashTableCore
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::ListHashTable< T, Key, Hash >

STL conforming hash table using contiguous lists rather than linked lists.

Note: Is slower to insert than the standard HashTable, but should be more memory efficient and faster to access.

Source files

Definition at line 56 of file ListHashTable.H.

Member Typedef Documentation

◆ iterator

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

Definition at line 136 of file ListHashTable.H.

◆ const_iterator

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

Definition at line 148 of file ListHashTable.H.

◆ value_type

typedef T value_type

Type of values the ListHashTable contains.

Definition at line 274 of file ListHashTable.H.

◆ reference

typedef T& reference

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

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

Definition at line 278 of file ListHashTable.H.

◆ const_reference

typedef const T& const_reference

Type that can be used for storing into constant.

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

Definition at line 283 of file ListHashTable.H.

◆ size_type

typedef label size_type

The type that can represent the size of a ListHashTable.

Definition at line 286 of file ListHashTable.H.

Constructor & Destructor Documentation

◆ ListHashTable() [1/4]

ListHashTable ( const label  size = 128)

Construct given initial table size.

Definition at line 62 of file ListHashTable.C.

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ListHashTable() [2/4]

ListHashTable ( Istream is,
const label  size = 128 
)

Construct from Istream.

Definition at line 34 of file ListHashTableIO.C.

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

Here is the call graph for this function:

◆ ListHashTable() [3/4]

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

Copy constructor.

Definition at line 82 of file ListHashTable.C.

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

Here is the call graph for this function:

◆ ListHashTable() [4/4]

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

Move constructor.

Definition at line 97 of file ListHashTable.C.

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

Here is the call graph for this function:

◆ ~ListHashTable()

Destructor.

Definition at line 115 of file ListHashTable.C.

Member Function Documentation

◆ size()

Foam::label size ( ) const
inline

Return number of elements in table.

Definition at line 42 of file ListHashTableI.H.

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

Here is the caller graph for this function:

◆ empty()

bool empty ( ) const
inline

Return true if the hash table is empty.

Definition at line 49 of file ListHashTableI.H.

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

Here is the call graph for this function:

◆ found()

bool found ( const Key &  key) const

Return true if hashed entry is found in table.

Definition at line 122 of file ListHashTable.C.

References ListHashTable< T, Key, Hash >::find(), forAll, and InfoInFunction.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [1/2]

Foam::ListHashTable< 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 152 of file ListHashTable.C.

References ListHashTable< T, Key, Hash >::end(), forAll, and InfoInFunction.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find() [2/2]

Foam::ListHashTable< 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 184 of file ListHashTable.C.

References ListHashTable< T, Key, Hash >::cend(), forAll, and InfoInFunction.

Here is the call graph for this function:

◆ toc()

Foam::List< Key > toc ( ) const

Return the table of contents.

Definition at line 214 of file ListHashTable.C.

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

Here is the call graph for this function:

◆ printInfo()

◆ insert()

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

Insert a new hashed entry.

Definition at line 57 of file ListHashTableI.H.

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

Here is the caller graph for this function:

◆ set()

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

Assign a new hashed entry, overwriting existing entries.

Definition at line 68 of file ListHashTableI.H.

◆ erase() [1/3]

bool erase ( const iterator it)

Erase an hashed entry specified by given iterator.

Definition at line 287 of file ListHashTable.C.

References ListHashTable< T, Key, Hash >::end(), InfoInFunction, List< T >::setSize(), and List< T >::size().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase() [2/3]

bool erase ( const Key &  key)

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

Definition at line 342 of file ListHashTable.C.

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

Here is the call graph for this function:

◆ resize()

void resize ( const label  newSize)

◆ erase() [3/3]

Foam::label erase ( const ListHashTable< T, Key, Hash > &  rhs)

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

Return the number of elements removed

Definition at line 359 of file ListHashTable.C.

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

Here is the call graph for this function:

◆ clear()

void clear ( )

Clear all entries from table.

Definition at line 420 of file ListHashTable.C.

References forAll.

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

Here is the caller graph for this function:

◆ clearStorage()

void clearStorage ( )

Clear the table entries and the table itself.

Equivalent to clear() followed by resize(1)

Definition at line 433 of file ListHashTable.C.

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

Here is the call graph for this function:

◆ transfer()

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

Transfer the contents of the argument table into this table.

and annul the argument table.

Definition at line 442 of file ListHashTable.C.

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator[]() [1/2]

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

Find and return an hashed entry.

Definition at line 80 of file ListHashTableI.H.

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

Here is the call graph for this function:

◆ operator[]() [2/2]

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

Find and return an hashed entry.

Definition at line 97 of file ListHashTableI.H.

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

Here is the call graph for this function:

◆ operator()()

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

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

Definition at line 115 of file ListHashTableI.H.

References Foam::vtkWriteOps::insert(), and T.

Here is the call graph for this function:

◆ operator=() [1/2]

◆ operator=() [2/2]

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

Move assignment operator.

Definition at line 508 of file ListHashTable.C.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, and ListHashTable< T, Key, Hash >::transfer().

Here is the call graph for this function:

◆ operator==()

bool operator== ( const ListHashTable< 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 526 of file ListHashTable.C.

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

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

The opposite of the equality operation.

Definition at line 548 of file ListHashTable.C.

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

Here is the call graph for this function:

◆ begin() [1/2]

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

Iterator set to the beginning of the ListHashTable.

Definition at line 326 of file ListHashTableI.H.

References forAll, and Foam::Info.

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

Here is the caller graph for this function:

◆ end() [1/2]

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

Iterator set to beyond the end of the ListHashTable.

Definition at line 350 of file ListHashTableI.H.

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

Here is the caller graph for this function:

◆ cbegin()

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

const_iterator set to the beginning of the ListHashTable

Definition at line 358 of file ListHashTableI.H.

References forAll, and Foam::Info.

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

Here is the caller graph for this function:

◆ cend()

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

◆ begin() [2/2]

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

const_iterator set to the beginning of the ListHashTable

Definition at line 390 of file ListHashTableI.H.

◆ end() [2/2]

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

const_iterator set to beyond the end of the ListHashTable

Definition at line 398 of file ListHashTableI.H.

Friends And Related Function Documentation

◆ Iterator< T &, ListHashTable< T, Key, Hash > &>

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

Definition at line 157 of file ListHashTable.H.

◆ Iterator< const T &, const ListHashTable< T, Key, Hash > &>

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

Definition at line 163 of file ListHashTable.H.

◆ operator>>

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

◆ operator

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

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