sipxportlib  Version 3.3
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
UtlHashMap Class Reference

#include <UtlHashMap.h>

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

Public Member Functions

 UtlHashMap ()
 Default Constructor. More...
 
virtual ~UtlHashMap ()
 Destructor. More...
 
virtual UtlHashMapclone () const
 Make an off the heap copy of this object. More...
 
UtlContainableinsertKeyAndValue (UtlContainable *key, UtlContainable *value)
 Inserts a key and value pair into the hash map. More...
 
UtlContainableinsert (UtlContainable *obj)
 Inserts the designated containable object into the list with a NULL value. More...
 
UtlContainableremove (UtlContainable *key)
 Remove the designated key and its associated value. More...
 
UtlContainableremoveReference (const UtlContainable *key)
 Remove the designated key and its associated value. More...
 
UtlContainableremoveKeyAndValue (const UtlContainable *key, UtlContainable *&value)
 Remove the designated key and its associated value. More...
 
virtual UtlBoolean destroy (UtlContainable *key)
 Removes the designated key and its associated value from the map and frees the key and the value (if not NULL) by calling delete. More...
 
virtual void destroyAll ()
 Removes all elements from the hash map and deletes each element. More...
 
virtual void removeAll ()
 Removes all elements from the hash map without deleting the elements. More...
 
UtlContainablefindValue (const UtlContainable *key) const
 Return the value for a given key or NULL if not found. More...
 
virtual UtlContainablefind (const UtlContainable *key) const
 Return the designated key if found otherwise NULL. More...
 
size_t entries () const
 Return the total number of keys in the hash map. More...
 
UtlBoolean isEmpty () const
 Return true if the hash map is empty (entries() == 0), otherwise false. More...
 
UtlBoolean contains (const UtlContainable *key) const
 Return true if the hash map includes an entry with the specified key. More...
 
virtual UtlContainableType getContainableType () const
 Get the ContainableType for the hash bag as a contained object. More...
 
void copyInto (UtlHashMap &map) const
 Make a copy of all of the items BY POINTER in (*this) instance into the given map. More...
 
OsStatus deepCopyInto (UtlHashMap &map) const
 
size_t numberOfBuckets () const
 The current number of buckets in the hash. More...
 
- Public Member Functions inherited from UtlContainer
 UtlContainer ()
 
virtual ~UtlContainer ()
 
virtual unsigned hash () const
 
virtual int compareTo (const UtlContainable *otherObject) const
 
- Public Member Functions inherited from UtlContainable
virtual ~UtlContainable ()
 
unsigned directHash () const
 Provides a hash function that uses the object pointer as the hash value. More...
 
virtual UtlBoolean isEqual (UtlContainable const *) const
 Test this object to another object for equality. More...
 
virtual UtlBoolean isInstanceOf (const UtlContainableType type) const
 Determine if this object is a derivative of the specified UtlContainableType. More...
 

Static Public Attributes

static const UtlContainableType TYPE = "UtlHashMap"
 
- Static Public Attributes inherited from UtlContainer
static const UtlContainableType TYPE = "UtlContainer"
 
- Static Public Attributes inherited from UtlContainable
static const UtlContainableType TYPE = "UtlContainable"
 

Protected Member Functions

void resizeIfNeededAndSafe ()
 If the Hash is too full, add additional buckets. More...
 
- Protected Member Functions inherited from UtlContainer
void addIterator (UtlIterator *newIterator) const
 Add an iterator to the list to be notified of changes to this container. More...
 
void removeIterator (UtlIterator *existingIterator) const
 Called from iterator destructor to prevent further notices. More...
 
void invalidateIterators ()
 Call the invalidate method on all iterators. More...
 

Protected Attributes

size_t mElements
 number of UtlContainable objects in this UtlHashMap More...
 
size_t mBucketBits
 number of bits used to index the buckets More...
 
UtlChainmpBucket
 an array of 2**n UtlChain elements, each used as a list header. More...
 
- Protected Attributes inherited from UtlContainer
OsBSem mContainerLock
 Must be taken when making any change to container state. More...
 
UtlChain mIteratorList
 

Static Protected Attributes

static const UtlContainableINTERNAL_NULL = &INTERNAL_NULL_OBJECT
 

Friends

class UtlHashMapIterator
 

Additional Inherited Members

- Static Public Member Functions inherited from UtlContainer
static void acquireIteratorConnectionLock ()
 Lock the linkage between containers and iterators. More...
 
static void releaseIteratorConnectionLock ()
 Unlock the linkage between containers and iterators. More...
 
- Static Public Member Functions inherited from UtlContainable
static unsigned stringHash (char const *value)
 Provides a hash function appropriate for null-terminated string values. More...
 
static UtlBoolean areSameTypes (const UtlContainableType type1, const UtlContainableType type2)
 Are UtlContainable types the same. More...
 

Detailed Description

UtlHashMap is a container object that allows you to store keys and values.

Key must be unique (testing for equality using the UtlContainer::isEquals() method).

Constructor & Destructor Documentation

Default Constructor.

~UtlHashMap ( )
virtual

Destructor.

Member Function Documentation

UtlHashMap * clone ( ) const
virtual

Make an off the heap copy of this object.

Make an off the heap, deep copy of this object.

< Class type used for runtime checking

UtlContainable * insertKeyAndValue ( UtlContainable key,
UtlContainable value 
)

Inserts a key and value pair into the hash map.

If the inserted key is already in the table, this method fails (returns NULL - note that this means if value is NULL, then you can't tell whether there was an error or not). To replace the value for a given key, the old value must be Removed before the new value is inserted.

Returns
the key on success, otherwise NULL
UtlContainable * insert ( UtlContainable obj)
virtual

Inserts the designated containable object into the list with a NULL value.

If there is an equal key in the UtlHashMap already, the insert will fail.

See also
note regarding use of NULL value in insertKeyAndValue().
Returns
the object if successful, otherwise NULL

Implements UtlContainer.

UtlContainable * remove ( UtlContainable key)

Remove the designated key and its associated value.

Returns
the key or NULL if not found
UtlContainable * removeReference ( const UtlContainable key)
virtual

Remove the designated key and its associated value.

Returns
the key or NULL if not found

Implements UtlContainer.

UtlContainable * removeKeyAndValue ( const UtlContainable key,
UtlContainable *&  value 
)

Remove the designated key and its associated value.

The pointer of value is returned as part of the call if successful.

Returns
the key or NULL if not found
UtlBoolean destroy ( UtlContainable key)
virtual

Removes the designated key and its associated value from the map and frees the key and the value (if not NULL) by calling delete.

Parameters
pointerto a UtlContainable for which key->operator==(the actual key)
Returns
the key or NULL if not found

Implements UtlContainer.

void destroyAll ( )
virtual

Removes all elements from the hash map and deletes each element.

Implements UtlContainer.

void removeAll ( )
virtual

Removes all elements from the hash map without deleting the elements.

Implements UtlContainer.

UtlContainable * findValue ( const UtlContainable key) const

Return the value for a given key or NULL if not found.

UtlContainable * find ( const UtlContainable key) const
virtual

Return the designated key if found otherwise NULL.

Implements UtlContainer.

size_t entries ( ) const
virtual

Return the total number of keys in the hash map.

Implements UtlContainer.

UtlBoolean isEmpty ( void  ) const
virtual

Return true if the hash map is empty (entries() == 0), otherwise false.

Implements UtlContainer.

UtlBoolean contains ( const UtlContainable key) const
virtual

Return true if the hash map includes an entry with the specified key.

Implements UtlContainer.

UtlContainableType getContainableType ( ) const
virtual

Get the ContainableType for the hash bag as a contained object.

Get the ContainableType for the hash map as a contained object.

Reimplemented from UtlContainer.

void copyInto ( UtlHashMap map) const

Make a copy of all of the items BY POINTER in (*this) instance into the given map.

It does not clear the given map. IF USING destroyAll call, be sure to call this on only ONE map instance.

OsStatus deepCopyInto ( UtlHashMap map) const

This does a deep copy of the object in this UtlHashMap. WARNING: buyer beware, all objects (both keys and values) MUST be derived from UtlCopyableContainable or this method will fail. The clone method is invoked on both keys and values to create copies into the given map. The given map does not need to be empty, but if the key already exists, the copy will fail.

Parameters
map- target UtlHashMap to copy key/value pairs to.
Returns
OS_NAME_IN_USE if key already exists in map OS_NOT_SUPPORTED if any key or object is not derived from UtlCopyableContainable
size_t numberOfBuckets ( ) const
inline

The current number of buckets in the hash.

void resizeIfNeededAndSafe ( )
inlineprotected

If the Hash is too full, add additional buckets.

Assumes that the caller is holding the mContainerLock.

This calls resize to actually do the resize if it is safe.

Friends And Related Function Documentation

friend class UtlHashMapIterator
friend

Member Data Documentation

const UtlContainableType TYPE = "UtlHashMap"
static
const UtlContainable * INTERNAL_NULL = &INTERNAL_NULL_OBJECT
staticprotected
size_t mElements
protected

number of UtlContainable objects in this UtlHashMap

size_t mBucketBits
protected

number of bits used to index the buckets

UtlChain* mpBucket
protected

an array of 2**n UtlChain elements, each used as a list header.