Jive reference manual
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
jem::util::HashDictionary Class Reference

Implements a dictionary based on a hash table. More...

#include <jem/util/HashDictionary.h>

Inheritance diagram for jem::util::HashDictionary:
Inheritance graph

Public Types

typedef Dictionary Super
 
typedef HashDictionary Self
 

Public Member Functions

 HashDictionary ()
 Constructs an empty hash dictionary. More...
 
virtual ClassgetClass () const
 Returns the Class instance representing the runtime class of this object. More...
 
virtual void readFrom (io::ObjectInput &in)
 
virtual void writeTo (io::ObjectOutput &out) const
 
virtual Ref< Objectclone () const
 
virtual Ref< DictionaryEnumeratorgetDictEnumerator () const
 Returns an enumerator over this dictionary. More...
 
virtual bool find (Ref< Object > &value, const String &key) const
 Searches for an object associated with a specific key. More...
 
virtual void insert (const String &key, const Ref< Object > &value)
 Inserts a key/value pair into this dictionary. More...
 
virtual void erase (const String &key)
 Deletes a key/value pair from this dictionary. More...
 
virtual void clear ()
 Deletes all objects from this collection. More...
 
virtual void reserve (int n)
 Expands the hash table for additional key/value pairs. More...
 
virtual void trimToSize ()
 De-allocates non-used memory. More...
 
virtual int capacity () const
 Returns the capacity of this dictionary. More...
 
virtual int size () const
 Returns the number of objects in this collection. More...
 
- Public Member Functions inherited from jem::util::Dictionary
Ref< DictionaryEnumeratorenumerate () const
 Returns an enumerator over this dictionary. More...
 
virtual Ref< EnumeratorgetEnumerator () const
 Returns an enumerator over this dictionary. More...
 
virtual bool contains (const String &key) const
 Checks whether this dictionary contains a specific key. More...
 
virtual Ref< Objectget (const String &key) const
 Returns the object associated with a specific key. More...
 
virtual bool add (const Ref< Object > &obj)
 Adds a key/value pair to this dictionary. More...
 
- Public Member Functions inherited from jem::util::ObjectCollection
Ref< Enumeratorenumerate () const
 Returns an enumerator over this collection. More...
 
- Public Member Functions inherited from jem::Object
virtual String toString () const
 Returns a short textual description of this object. More...
 
virtual long hashValue () const
 Returns a hash value for this object. More...
 
virtual bool equals (const Ref< Object > &obj) const
 Tests whether two objects are equal. More...
 
Ref< Objectclone () const
 Returns a copy of this object. More...
 

Static Public Member Functions

static ClassmakeClass ()
 
static ClassgetType ()
 
- Static Public Member Functions inherited from jem::util::Dictionary
static ClassmakeClass ()
 
static ClassgetType ()
 
- Static Public Member Functions inherited from jem::util::ObjectCollection
static ClassmakeClass ()
 
static ClassgetType ()
 
- Static Public Member Functions inherited from jem::Object
static ClassgetType ()
 Returns the Class instance representing the Object class. More...
 

Protected Member Functions

virtual ~HashDictionary ()
 
- Protected Member Functions inherited from jem::util::Dictionary
virtual ~Dictionary ()
 
void readFrom_ (io::ObjectInput &in)
 Reads the contents of this dictionary from an object input stream. More...
 
void writeTo_ (io::ObjectOutput &out) const
 Writes the contents of this dictionary to an object output stream. More...
 
void clone_ (const Dictionary &rhs)
 Makes a deep copy of another dictionary. More...
 
- Protected Member Functions inherited from jem::util::ObjectCollection
virtual ~ObjectCollection ()
 
void clone_ (const ObjectCollection &rhs)
 Makes a deep copy of another collection. More...
 
void readFrom_ (io::ObjectInput &in)
 Reads the contents of this collection from an object input stream. More...
 
void writeTo_ (io::ObjectOutput &out) const
 Writes the contents of this collection to an object output stream. More...
 
- Protected Member Functions inherited from jem::Collectable
 Collectable ()
 Creates an empty Collectable. More...
 
 ~Collectable ()
 Frees resources. More...
 
- Protected Member Functions inherited from jem::util::Enumerable
virtual ~Enumerable ()
 
- Protected Member Functions inherited from jem::Interface
virtual ~Interface ()
 Empty destructor. More...
 
- Protected Member Functions inherited from jem::Clonable
virtual ~Clonable ()
 
virtual void emitVTable_ ()
 
- Protected Member Functions inherited from jem::io::Serializable
virtual ~Serializable ()
 
virtual void emitVtableFunc_ ()
 

Detailed Description

The HashDictionary class uses a hash table to implement the interface defined by the Dictionary class. It has two important properties. First, the time it takes to insert or to find a key/value pair does not – on average – depend on the total number key/value pairs. Second, the order of a HashDictionary is not defined. That is, an enumerator returned by a HashDictionary iterates over the key/value pairs in a arbitrary order.

Reading from a HashDictionary is thread safe. To be precise, the following functions may be called by multiple threads concurrently: enumerate(), getDictEnumerator(), find() and size(). All other functions are not thread safe.

Examples:
meshgen.cpp.

Member Typedef Documentation

Constructor & Destructor Documentation

jem::util::HashDictionary::HashDictionary ( )

Constructs an empty HashDictionary.

Postcondition
size() == 0
virtual jem::util::HashDictionary::~HashDictionary ( )
protectedvirtual

Member Function Documentation

static Class* jem::util::HashDictionary::makeClass ( )
static
static Class* jem::util::HashDictionary::getType ( )
static
virtual Class* jem::util::HashDictionary::getClass ( ) const
virtual

Returns a pointer to the Class instance representing the runtime class of this object. If T denotes the runtime class of this object, then this function is equivalent with T::getType(). The pointer is valid during the entire lifetime of the program.

Returns
A pointer to the Class instance representing the runtime class of this object.

Reimplemented from jem::util::Dictionary.

virtual void jem::util::HashDictionary::readFrom ( io::ObjectInput in)
virtual

Implements jem::io::Serializable.

virtual void jem::util::HashDictionary::writeTo ( io::ObjectOutput out) const
virtual

Implements jem::io::Serializable.

virtual Ref<Object> jem::util::HashDictionary::clone ( ) const
virtual

Implements jem::Clonable.

virtual Ref<DictionaryEnumerator> jem::util::HashDictionary::getDictEnumerator ( ) const
virtual

Returns a DictionaryEnumerator that can be used to iterate over all key/value pairs in this dictionary. The enumerator points to the first key/value pair, or to the special end object if this dictionary is empty.

This dictionary may not be structurally modified as long as one or more enumerators are pointing to it.

Returns
A DictionaryEnumerator over this dictionary.

Implements jem::util::Dictionary.

virtual bool jem::util::HashDictionary::find ( Ref< Object > &  value,
const String key 
) const
virtual

Searches for the object that is associated with the key key. If the object is found, then its address is stored in the output parameter value and true is returned. Otherwise, false is returned and the output parameter value is not modified.

This function may not be called if an enumerator points to this dictionary.

Parameters
value- a reference in which the address of the object to be found is stored.
key- the key associated with the object to be found.
Returns
true if this dictionary contains the key key, and false otherwise.

Implements jem::util::Dictionary.

virtual void jem::util::HashDictionary::insert ( const String key,
const Ref< Object > &  value 
)
virtual

Inserts a key/value pair in this dictionary. If this dictionary already contains the key key, then its associated value is replaced by the parameter value.

This function may not be called if an enumerator points to this dictionary.

Parameters
key- a key string.
value- the object associated with the key key.

Implements jem::util::Dictionary.

virtual void jem::util::HashDictionary::erase ( const String key)
virtual

Deletes the key key and its associated value from this dictionary. If this dictionary does not contain the specified key, then this function has no effect.

This function may not be called if an enumerator points to this dictionary.

Parameters
key- the key to be deleted.

Implements jem::util::Dictionary.

virtual void jem::util::HashDictionary::clear ( )
virtual

Deletes all objects from this collection.

This function may not be called if an enumerator points to this collection.

Postcondition
this->size() == 0

Implements jem::util::ObjectCollection.

virtual void jem::util::HashDictionary::reserve ( int  n)
virtual

Expands the internal hash table and pre-allocates memory for additional key/value pairs. The input arguments n specifies the total number of key/value pairs that will be stored in this dictionary. This function speeds up subsequent calls to the member functions insert() and add().

Note that the internal hash table of this dictionary is resized automatically when needed, even if this function is not called. By calling this function, however, you can reduce the number of times that the hash table has to be resized.

This function may not be called if an enumerator points to this collection.

Reimplemented from jem::util::ObjectCollection.

virtual void jem::util::HashDictionary::trimToSize ( )
virtual

De-allocates non-used memory and shrinks the internal hash table if possible.

This function may not be called if an enumerator points to this collection.

Reimplemented from jem::util::ObjectCollection.

virtual int jem::util::HashDictionary::capacity ( ) const
virtual

Returns the number of key/value pairs that this dictionary can contain without having to expand its internal data structures.

Reimplemented from jem::util::ObjectCollection.

virtual int jem::util::HashDictionary::size ( ) const
virtual

Returns the number of objects in this collection.

Returns
The number of objects in this collection.

Implements jem::util::ObjectCollection.