Data Structures | Public Types | Public Member Functions | Data Fields | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
StaticHashTable Class Reference

STL conforming hash table. More...

Inheritance diagram for StaticHashTable:
Inheritance graph
[legend]
Collaboration diagram for StaticHashTable:
Collaboration graph
[legend]

Data Structures

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. More...
 
typedef Treference
 Type that can be used for storing into StaticHashTable::value_type. More...
 
typedef label size_type
 The type that can represent the size of a StaticHashTable. More...
 

Public Member Functions

 StaticHashTable (const label size=128)
 Construct given initial table size. More...
 
 StaticHashTable (Istream &, const label size=128)
 Construct from Istream. More...
 
 StaticHashTable (const StaticHashTable< T, Key, Hash > &)
 Construct as copy. More...
 
 StaticHashTable (const Xfer< StaticHashTable< T, Key, Hash > > &)
 Construct by transferring the parameter contents. More...
 
 ~StaticHashTable ()
 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 StaticHashTable< 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 (StaticHashTable< T, Key, Hash > &)
 Transfer the contents of the argument table into this table. More...
 
Xfer< StaticHashTable< T, Key, Hash > > xfer ()
 Transfer contents to the Xfer container. 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 StaticHashTable< T, Key, Hash > &)
 Assignment. More...
 
bool operator== (const StaticHashTable< T, Key, Hash > &) const
 Equality. Two hash tables are equal if all contents of first are. More...
 
bool operator!= (const StaticHashTable< T, Key, Hash > &) const
 The opposite of the equality operation. More...
 
iterator begin ()
 Iterator set to the beginning of the StaticHashTable. More...
 
const iteratorend ()
 Iterator set to beyond the end of the StaticHashTable. More...
 
const_iterator cbegin () const
 const_iterator set to the beginning of the StaticHashTable More...
 
const const_iteratorcend () const
 const_iterator set to beyond the end of the StaticHashTable More...
 
const_iterator begin () const
 const_iterator set to the beginning of the StaticHashTable More...
 
const const_iteratorend () const
 const_iterator set to beyond the end of the StaticHashTable More...
 

Data Fields

const typedef Tconst_reference
 Type that can be used for storing into constant. More...
 

Private Member Functions

label hashKeyIndex (const Key &) const
 Return the hash index of the Key within the current table size. More...
 
bool set (const Key &, const T &newElmt, bool protect)
 Assign a new hashed entry to a possibly already existing key. More...
 

Static Private Member Functions

static label canonicalSize (const label)
 Return a canonical (power-of-two) size. More...
 

Private Attributes

List< List< Key > > keys_
 The lookup keys, ordered per hash value. More...
 
List< List< T > > objects_
 For each key the corresponding object. More...
 
label nElmts_
 The current number of elements in table. More...
 
iterator endIter_
 Iterator returned by end() More...
 
const_iterator endConstIter_
 const_iterator returned by end() More...
 

Friends

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

Detailed Description

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

Member Typedef Documentation

◆ iterator

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

Definition at line 138 of file StaticHashTable.H.

◆ const_iterator

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

Definition at line 150 of file StaticHashTable.H.

◆ value_type

typedef T value_type

Type of values the StaticHashTable contains.

Definition at line 276 of file StaticHashTable.H.

◆ reference

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

◆ size_type

typedef label size_type

The type that can represent the size of a StaticHashTable.

Definition at line 288 of file StaticHashTable.H.

Constructor & Destructor Documentation

◆ StaticHashTable() [1/4]

StaticHashTable ( const label  size = 128)

Construct given initial table size.

◆ StaticHashTable() [2/4]

StaticHashTable ( Istream ,
const label  size = 128 
)

Construct from Istream.

◆ StaticHashTable() [3/4]

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

Construct as copy.

◆ StaticHashTable() [4/4]

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

Construct by transferring the parameter contents.

◆ ~StaticHashTable()

Destructor.

Definition at line 118 of file StaticHashTable.C.

Member Function Documentation

◆ canonicalSize()

static label canonicalSize ( const  label)
staticprivate

Return a canonical (power-of-two) size.

◆ hashKeyIndex()

Foam::label hashKeyIndex ( const Key &  key) const
inlineprivate

Return the hash index of the Key within the current table size.

No checks for zero-sized tables.

Definition at line 35 of file StaticHashTableI.H.

◆ set() [1/2]

bool set ( const Key &  ,
const T newElmt,
bool  protect 
)
private

Assign a new hashed entry to a possibly already existing key.

◆ size()

Foam::label size ( ) const
inline

Return number of elements in table.

Definition at line 45 of file StaticHashTableI.H.

◆ empty()

bool empty ( ) const
inline

Return true if the hash table is empty.

Definition at line 52 of file StaticHashTableI.H.

◆ found()

bool found ( const Key &  key) const

Return true if hashed entry is found in table.

Definition at line 125 of file StaticHashTable.C.

Referenced by main().

Here is the caller graph for this function:

◆ find() [1/2]

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

◆ find() [2/2]

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

◆ toc()

Foam::List< Key > toc ( ) const

Return the table of contents.

Definition at line 221 of file StaticHashTable.C.

◆ printInfo()

Foam::Ostream & printInfo ( Ostream os) const

Print information.

Definition at line 61 of file StaticHashTableIO.C.

Referenced by main().

Here is the caller graph for this function:

◆ insert()

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

Insert a new hashed entry.

Definition at line 60 of file StaticHashTableI.H.

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

Here is the caller graph for this function:

◆ set() [2/2]

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

Assign a new hashed entry, overwriting existing entries.

◆ erase() [1/3]

bool erase ( const iterator it)

Erase an hashed entry specified by given iterator.

◆ erase() [2/3]

bool erase ( const Key &  key)

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

Definition at line 351 of file StaticHashTable.C.

◆ resize()

void resize ( const label  newSize)

Resize the hash table for efficiency.

Definition at line 389 of file StaticHashTable.C.

◆ erase() [3/3]

label erase ( const StaticHashTable< T, Key, Hash > &  )

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

Return the number of elements removed

◆ clear()

void clear ( )

Clear all entries from table.

Definition at line 430 of file StaticHashTable.C.

◆ clearStorage()

void clearStorage ( )

Clear the table entries and the table itself.

Equivalent to clear() followed by resize(1)

Definition at line 443 of file StaticHashTable.C.

◆ transfer()

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

Transfer the contents of the argument table into this table.

and annul the argument table.

Definition at line 452 of file StaticHashTable.C.

◆ xfer()

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

Transfer contents to the Xfer container.

Definition at line 82 of file StaticHashTableI.H.

◆ operator[]() [1/2]

T& operator[] ( const Key &  )
inline

Find and return an hashed entry.

◆ operator[]() [2/2]

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

Find and return an hashed entry.

◆ operator()()

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

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

Definition at line 126 of file StaticHashTableI.H.

◆ operator=()

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

Assignment.

Definition at line 479 of file StaticHashTable.C.

◆ operator==()

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

◆ operator!=()

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

The opposite of the equality operation.

Definition at line 539 of file StaticHashTable.C.

◆ begin() [1/2]

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

Iterator set to the beginning of the StaticHashTable.

Definition at line 337 of file StaticHashTableI.H.

◆ end() [1/2]

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

Iterator set to beyond the end of the StaticHashTable.

Definition at line 361 of file StaticHashTableI.H.

◆ cbegin()

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

const_iterator set to the beginning of the StaticHashTable

Definition at line 369 of file StaticHashTableI.H.

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

Here is the caller graph for this function:

◆ cend()

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

const_iterator set to beyond the end of the StaticHashTable

Definition at line 393 of file StaticHashTableI.H.

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

Here is the caller graph for this function:

◆ begin() [2/2]

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

const_iterator set to the beginning of the StaticHashTable

Definition at line 401 of file StaticHashTableI.H.

◆ end() [2/2]

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

const_iterator set to beyond the end of the StaticHashTable

Definition at line 409 of file StaticHashTableI.H.

Friends And Related Function Documentation

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

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

Definition at line 159 of file StaticHashTable.H.

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

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

Definition at line 165 of file StaticHashTable.H.

◆ operator>>

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

◆ operator

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

Field Documentation

◆ const_reference

const typedef 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 285 of file StaticHashTable.H.

◆ keys_

List<List<Key> > keys_
private

◆ objects_

List<List<T> > objects_
private

For each key the corresponding object.

Definition at line 116 of file StaticHashTable.H.

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

◆ nElmts_

label nElmts_
private

The current number of elements in table.

Definition at line 119 of file StaticHashTable.H.

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

◆ endIter_

iterator endIter_
private

Iterator returned by end()

Definition at line 386 of file StaticHashTable.H.

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

◆ endConstIter_

const_iterator endConstIter_
private

const_iterator returned by end()

Definition at line 389 of file StaticHashTable.H.

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


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