RWHashDictionary(3C++) RWHashDictionary(3C++)
NameRWHashDictionary - Rogue Wave library class
Synopsis
typedef RWHashDictionary Dictionary; // Smalltalk typedef.
#include <rw/hashdict.h>
RWHashDictionary a ;
Description
An RWHashDictionary represents a group of unordered values, accessible by
external keys. Duplicate keys are not allowed. RWHashDictionary is
implemented as a hash table of associations of keys and values. Both the
key and the value must inherit from the abstract base class
RWCollectable, with a suitable definition of the virtual function hash()
and isEqual() for the key. This class corresponds to the Smalltalk class
Dictionary.
Persistence
None
Public Constructors
RWHashDictionary(size_t n = RWDEFAULT_CAPACITY);
Construct an empty hashed dictionary using n hashing buckets.
RWHashDictionary(const RWHashDictionary& hd);
Copy constructor. A shallow copy of the collection hd is made.
Public Member Operators
void
operator=(const RWHashDictionary& hd);
Assignment operator. A shallow copy of the collection hd is made.
RWBoolean
operator<=(const RWHashDictionary& hd) const;
Returns TRUE if for every key-value pair in self, there is a
corresponding key in hd that isEqual. Their corresponding values must
also be equal. Note: If you inherit from RWHashDictionary in the
presence of the Standard C++ Library, we recommend that you override this
Page 1
RWHashDictionary(3C++) RWHashDictionary(3C++)
operator and explicitly forward the call. Overload resolution in C++
will choose the Standard Library provided global operators over inherited
class members. These global definitions are not appropriate for set-like
partial orderings.
RWBoolean
operator==(const RWHashDictionary& hd) const;
Returns TRUE if self and hd have the same number of entries and if for
every key-value pair in self, there is a corresponding key in hd that
isEqual. Their corresponding values must also be equal.
Public Member Functions
void
applyToKeyAndValue(RWapplyKeyAndValue ap, void* x);
Applies the user-supplied function pointed to by ap to each key-value
pair of the collection. Items are not visited in any particular order.
An untyped argument may be passed to the ap function through x.
RWBinaryTree
asBinaryTree();
RWBag
asBag() const;
RWSet
asOrderedCollection() const;
asSet() const;
RWOrdered
RWBinaryTree
asSortedCollection() const;
Converts the RWHashDictionary to an RWBag, RWSet, RWOrdered, or an
RWBinaryTree. Note that since a dictionary contains pairs of keys and
values, the result of this call will be a container holding
RWCollectableAssociations. Note also that the return value is a copy of
the data. This can be very expensive for large collections. Consider
using operator+=() to insert each RWCollectableAssociation from this
dictionary into a collection of your choice.
virtual RWspace
binaryStoreSize() const;
Inherited from class RWCollection.
virtual void
clear();
Page 2
RWHashDictionary(3C++) RWHashDictionary(3C++)
Redefined from class RWCollection. Removes all key-value pairs in the
collection.
virtual void
clearAndDestroy();
Redefined from class RWCollection. Removes all key-value pairs in the
collection, and deletes the key and the value.
virtual int
compareTo(const RWCollectable* a) const;
Inherited from class RWCollectable.
virtual RWBoolean
contains(const RWCollectable* target) const;
Inherited from class RWCollection.
virtual size_t
entries() const;
Inherited from class RWSet.
virtual RWCollectable*
find(const RWCollectable* target) const;
Redefined from class RWCollection. Returns the key which isEqual to the
object pointed to by target, or nil if no key was found.
RWCollectable*
findKeyAndValue(const RWCollectable* target,
RWCollectable*& v) const;
Returns the key which isEqual to the item pointed to by target, or nil if
no key was found. The value is put in v. You are responsible for
defining v before calling this function.
RWCollectable*
findValue(const RWCollectable* target) const;
Returns the value associated with the key which isEqual to the item
pointed to by target, or nil if no key was found.
Page 3
RWHashDictionary(3C++) RWHashDictionary(3C++)
RWCollectable*
findValue(const RWCollectable* target,
RWCollectable* newValue);
Returns the value associated with the key which isEqual to the item
pointed to by target, or nil if no key was found. Replaces the value
with newValue (if a key was found).
virtual unsigned
hash() const;
Inherited from class RWCollectable.
RWCollectable*
insertKeyAndValue(RWCollectable* key,RWCollectable* value);
Adds a key-value pair to the collection and returns the key if
successful, nil if the key is already in the collection.
virtual RWClassID
isA() const;
Redefined from class RWCollectable to return __RWHASHDICTIONARY.
virtual RWBoolean
isEmpty() const;
Inherited from class RWSet.
virtual RWBoolean
isEqual(const RWCollectable* a) const;
Inherited from class RWCollectable.
virtual size_t
occurrencesOf(const RWCollectable* target) const;
Inherited from class RWSet. Returns the number of keys which isEqual to
the item pointed to by target. Because duplicates are not allowed, this
function can only return 0 or 1.
virtual RWCollectable*
remove(const RWCollectable* target);
Page 4
RWHashDictionary(3C++) RWHashDictionary(3C++)
Redefined from class RWCollection. Removes the key and value pair where
the key isEqual to the item pointed to by target. Returns the key, or
nil if no match was found.
virtual void
removeAndDestroy(const RWCollectable* target);
Redefined from class RWCollection. Removes and deletes the key and value
pair where the key isEqual to the item pointed to by target. Note that
both the key and the value are deleted. Does nothing if the key is not
found.
RWCollectable*
removeKeyAndValue(const RWCollectable* target,
RWCollectable*& v);
Removes the key and value pair where the key isEqual to the item pointed
to by target. Returns the key, or nil if no match was found. The value
part of the removed pair is put in v. You are responsible for defining v
before calling this function.
void
resize(size_t n = 0);
Inherited from class RWSet.
virtual void
restoreGuts(RWvistream&);
virtual void
restoreGuts(RWFile&);
virtual void
saveGuts(RWvostream&) const;
virtual void
saveGuts(RWFile&) const;
Inherited from class RWCollection.
virtual RWCollection*
select(RWtestCollectable testfunc, void* x) const;
Evaluates the function pointed to by tst for the key of each item in the
RWHashDictionary. It inserts keys and values for which the function
returns TRUE into a new RWHashDictionary allocated off the heap and
returns a pointer to this new collection. Because the new dictionary is
allocated off the heap, you are responsible for deleting it when done.
This is a virtual function which hides the non-virtual function inherited
from RWCollection.
Page 5
RWHashDictionary(3C++) RWHashDictionary(3C++)
virtual RWCollection*
select(RWtestCollectablePair testfunc, void* x) const;
Evaluates the function pointed to by tst for both the key and the value
of each item in the RWHashDictionary. It inserts keys and values for
which the function returns TRUE into a new RWHashDictionary allocated off
the heap and returns a pointer to this new collection. Because the new
dictionary is allocated off the heap, you are responsible for deleting it
when done. This is a virtual function which hides the non-virtual
function inherited from RWCollection.
RWStringID
stringID();
(acts virtual) Inherited from class RWCollectable.
Page 6