BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 > Class Template Reference

#include <bdlc_hashtable.h>

Public Types

typedef bsls::Types::Int64 Handle
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (HashTable, bslma::UsesBslmaAllocator)
 
 HashTable (bsls::Types::Int64 capacityHint, bslma::Allocator *basicAllocator=0)
 
 HashTable (bsls::Types::Int64 capacityHint, const HASH1 &hashFunctor1, const HASH2 &hashFunctor2, bslma::Allocator *basicAllocator=0)
 
 ~HashTable ()
 Destroy this object.
 
bool insert (Handle *handle, const KEY &key)
 
bool insert (Handle *handle, const KEY &key, const VALUE &value)
 
void remove (const Handle &handle)
 
VALUE & value (const Handle &handle)
 
bsls::Types::Int64 capacity () const
 
bsls::Types::Int64 capacityHint () const
 
bool find (Handle *handle, const KEY &key) const
 
const KEY & key (const Handle &handle) const
 
bsls::Types::Int64 maxChain () const
 Return the maximum chain length encountered by this object.
 
bsls::Types::Int64 numCollisions () const
 Return the number of collisions encountered by this object.
 
bsls::Types::Int64 size () const
 Return the number of elements stored in this object.
 
bsls::Types::Int64 totalChain () const
 Return the total chain length encountered by this object.
 
const VALUE & value (const Handle &handle) const
 

Detailed Description

template<class KEY, class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
class bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >

This class is a double-hashed table. The VALUE template parameter is optional. The capacityHint specified at construction time will be used to compute the number of buckets (capacity) in this object. Also, two hash functions may optionally be specified at construction time. Elements can be inserted using the insert method. If the VALUE parameter is not bslmf::Nil, then both key and value must be supplied to the insert method. Otherwise, only the key should be supplied. The find method can be used to lookup elements by a specified key. The optional TRAITS parameter can be used to classify "null" and "removed" values. See the component-level documentation for more details.

See bdlc_hashtable

Member Typedef Documentation

◆ Handle

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
typedef bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::Handle

Data type to handle elements in the double-hashed table. This value is guaranteed to be between 0 and the capacity of the hash table.

Constructor & Destructor Documentation

◆ HashTable() [1/2]

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::HashTable ( bsls::Types::Int64  capacityHint,
bslma::Allocator basicAllocator = 0 
)
explicit

Create a double-hash table using the specified capacityHint. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 0 != capacityHint. Note that capacityHint can be either a positive integer or a negative integer. If capacityHint is positive, then the capacity of the hash table will be the first available prime number larger than, or equal to, capacityHint. Otherwise, the capacity of the hash table will be the first available prime number smaller than, or equal to, capacityHint. Also note that HASH1 will be used as the first hash function, and HASH2 will be used as the second hash function.

◆ HashTable() [2/2]

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::HashTable ( bsls::Types::Int64  capacityHint,
const HASH1 &  hashFunctor1,
const HASH2 &  hashFunctor2,
bslma::Allocator basicAllocator = 0 
)

Create a double-hash table with the specified capacityHint. Use the specified hashFunctor1 as the first hash function; use the specified hashFunctor2 as the second hash function. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless 0 != capacityHint, and hashFunction1 and hashFunction2 are valid. Note that capacityHint can be either a positive integer or a negative integer. If capacityHint is positive, then the capacity of the hash table will be the first available prime number larger than, or equal to, capacityHint. Otherwise, the capacity of the hash table will be the first available prime number smaller than, or equal to, capacityHint.

◆ ~HashTable()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::~HashTable ( )
inline

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION()

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::BSLMF_NESTED_TRAIT_DECLARATION ( HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >  ,
bslma::UsesBslmaAllocator   
)

◆ capacity()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::capacity ( ) const
inline

Return the maximum number of elements that can be stored in this object. Note that this value is computed based on the capacity hint used upon construction.

◆ capacityHint()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::capacityHint ( ) const
inline

Return the capacity hint that was used to determine the capacity of this object.

◆ find()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bool bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::find ( Handle handle,
const KEY &  key 
) const
inline

Find an element having the specified key; load a handle to the element into the specified handle. Return true if successful, and false otherwise.

◆ insert() [1/2]

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bool bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::insert ( Handle handle,
const KEY &  key 
)
inline

Insert an element with the specified key into this object; load a handle to the new element into the specified handle. Return true if successful, and false otherwise. The behavior is undefined unless key does not evaluate to a "null" or "removed" bucket, as defined by the parameterized TRAITS (see the component-level documentation for more details). Note that this method will fail to compile unless the VALUE parameter is bslmf::Nil.

◆ insert() [2/2]

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bool bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::insert ( Handle handle,
const KEY &  key,
const VALUE &  value 
)
inline

Insert an element with the specified key and the specified value into this object; load a handle to the new element into the specified handle. Return true if successful, and false otherwise. The behavior is undefined unless key and value do not evaluate to a "null" or "removed" bucket, as defined by the parameterized TRAITS (see the component-level documentation for more details). This method will fail to compile unless the VALUE parameter is not bslmf::Nil.

◆ key()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
const KEY & bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::key ( const Handle handle) const
inline

Return the reference to the non-modifiable key of the element identified by the specified handle. The behavior is undefined unless handle is valid.

◆ maxChain()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::maxChain ( ) const
inline

◆ numCollisions()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::numCollisions ( ) const
inline

◆ remove()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
void bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::remove ( const Handle handle)
inline

Remove the element identified by the specified handle from this object. The behavior is undefined unless handle is valid. Note that handle will become invalid when this method returns.

◆ size()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::size ( ) const
inline

◆ totalChain()

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::totalChain ( ) const
inline

◆ value() [1/2]

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
VALUE & bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::value ( const Handle handle)
inline

Return the reference to the modifiable value of the element identified by the specified handle. The behavior is undefined unless handle is valid. Note that this method will fail to compile unless the VALUE parameter is not bslmf::Nil.

◆ value() [2/2]

template<class KEY , class VALUE , class TRAITS , class HASH1 , class HASH2 >
const VALUE & bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::value ( const Handle handle) const
inline

Return the reference to the non-modifiable value of the element identified by the specified handle. The behavior is undefined unless handle is valid. Note that this method will fail to compile unless the VALUE parameter is not bslmf::Nil.


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