Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions

bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 > Class Template Reference

#include <bdlc_hashtable.h>

List of all members.

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 ()
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
bsls::Types::Int64 numCollisions () const
bsls::Types::Int64 size () const
bsls::Types::Int64 totalChain () const
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 Component bdlc_hashtable


Member Typedef Documentation

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

Constructor & Destructor Documentation

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
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.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
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.

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

Destroy this object.


Member Function Documentation

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   
)
template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bool bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::insert ( Handle handle,
const KEY &  key 
)

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.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bool bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::insert ( Handle handle,
const KEY &  key,
const VALUE &  value 
)

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.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
void bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::remove ( const Handle handle  ) 

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.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
VALUE& bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::value ( const Handle handle  ) 

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.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::capacity (  )  const

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.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::capacityHint (  )  const

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

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bool bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::find ( Handle handle,
const KEY &  key 
) const

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

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
const KEY& bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::key ( const Handle handle  )  const

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

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::maxChain (  )  const

Return the maximum chain length encountered by this object.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::numCollisions (  )  const

Return the number of collisions encountered by this object.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::size (  )  const

Return the number of elements stored in this object.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
bsls::Types::Int64 bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::totalChain (  )  const

Return the total chain length encountered by this object.

template<class KEY , class VALUE = bslmf::Nil, class TRAITS = HashTableDefaultTraits, class HASH1 = HashTableDefaultHash1, class HASH2 = HashTableDefaultHash2>
const VALUE& bdlc::HashTable< KEY, VALUE, TRAITS, HASH1, HASH2 >::value ( const Handle handle  )  const

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: