Jive reference manual
|
Implements a dictionary based on a hash table. More...
#include <jem/util/HashDictionary.h>
Public Types | |
typedef Dictionary | Super |
typedef HashDictionary | Self |
Public Member Functions | |
HashDictionary () | |
Constructs an empty hash dictionary. More... | |
virtual Class * | getClass () 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< Object > | clone () const |
virtual Ref< DictionaryEnumerator > | getDictEnumerator () 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< DictionaryEnumerator > | enumerate () const |
Returns an enumerator over this dictionary. More... | |
virtual Ref< Enumerator > | getEnumerator () 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< Object > | get (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< Enumerator > | enumerate () 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< Object > | clone () const |
Returns a copy of this object. More... | |
Static Public Member Functions | |
static Class * | makeClass () |
static Class * | getType () |
Static Public Member Functions inherited from jem::util::Dictionary | |
static Class * | makeClass () |
static Class * | getType () |
Static Public Member Functions inherited from jem::util::ObjectCollection | |
static Class * | makeClass () |
static Class * | getType () |
Static Public Member Functions inherited from jem::Object | |
static Class * | getType () |
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_ () |
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.
jem::util::HashDictionary::HashDictionary | ( | ) |
Constructs an empty HashDictionary
.
size() == 0
|
protectedvirtual |
|
static |
|
static |
|
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.
Class
instance representing the runtime class of this object. Reimplemented from jem::util::Dictionary.
|
virtual |
Implements jem::io::Serializable.
|
virtual |
Implements jem::io::Serializable.
Implements jem::Clonable.
|
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.
DictionaryEnumerator
over this dictionary. Implements jem::util::Dictionary.
|
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.
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. |
true
if this dictionary contains the key key, and false
otherwise. Implements jem::util::Dictionary.
|
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.
key | - a key string. |
value | - the object associated with the key key. |
Implements jem::util::Dictionary.
|
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.
key | - the key to be deleted. |
Implements jem::util::Dictionary.
|
virtual |
Deletes all objects from this collection.
This function may not be called if an enumerator points to this collection.
this->size() == 0
Implements jem::util::ObjectCollection.
|
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 |
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 |
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 |
Returns the number of objects in this collection.
Implements jem::util::ObjectCollection.