rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWHashDictionary Class Reference
[RWCollectable-derived]

Represents a group of unordered values, accessible by external keys. More...

#include <rw/hashdict.h>

Inheritance diagram for RWHashDictionary:
RWSet RWHashTable RWCollection RWCollectable RWIdentityDictionary

List of all members.

Public Member Functions

virtual RWCollectablenewSpecies () const
virtual RWClassID isA () const
 RWHashDictionary (size_t n=RWCollection::DEFAULT_CAPACITY)
 RWHashDictionary (const RWHashDictionary &hd)
 RWHashDictionary (RWHashDictionary &&hd)
virtual ~RWHashDictionary ()
void operator= (const RWHashDictionary &hd)
void operator= (RWHashDictionary &&hd)
bool operator<= (const RWHashDictionary &hd) const
bool operator<= (const RWSet &hd) const
bool operator<= (const RWHashTable &hd) const
bool operator== (const RWHashDictionary &hd) const
bool operator== (const RWHashTable &hd) const
void applyToKeyAndValue (RWapplyKeyAndValue ap, void *x)
virtual void clear ()
virtual void clearAndDestroy ()
virtual RWCollectablefind (const RWCollectable *target) const
RWCollectablefindKeyAndValue (const RWCollectable *target, RWCollectable *&v) const
RWCollectablefindValue (const RWCollectable *target) const
RWCollectablefindValue (const RWCollectable *target, RWCollectable *newValue) const
RWCollectableinsertKeyAndValue (RWCollectable *key, RWCollectable *value)
virtual bool isEqual (const RWCollectable *) const
virtual RWCollectableremove (const RWCollectable *target)
virtual void removeAndDestroy (const RWCollectable *target)
RWCollectableremoveKeyAndValue (const RWCollectable *target, RWCollectable *&v)
virtual RWCollectionselect (RWtestCollectable tst, void *x) const
virtual RWCollectionselect (RWtestCollectablePair testfunc, void *x) const
virtual RWIteratornewIterator ()
virtual RWConstIteratornewConstIterator () const

Static Public Member Functions

static RWClassID classIsA ()

Private Member Functions

virtual RWCollectableinsert (RWCollectable *a)

Detailed 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.

Synopsis

 typedef RWHashDictionary Dictionary;  // Smalltalk typedef.
 #include <rw/hashdict.h>
 RWHashDictionary  a ;

Persistence

Polymorphic


Constructor & Destructor Documentation

RWHashDictionary::RWHashDictionary ( size_t  n = RWCollection::DEFAULT_CAPACITY  ) 

Constructs an empty hashed dictionary using n hashing buckets.

RWHashDictionary::RWHashDictionary ( const RWHashDictionary hd  ) 

Copy constructor. Makes a shallow copy of the collection hd.

RWHashDictionary::RWHashDictionary ( RWHashDictionary &&  hd  )  [inline]

Move constructor. The constructed RWHashDictionary takes ownership of the data owned by hd.

Condition:
This method is only available on platforms with rvalue reference support.
virtual RWHashDictionary::~RWHashDictionary (  )  [virtual]

Calls clear().


Member Function Documentation

void RWHashDictionary::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.

static RWClassID RWHashDictionary::classIsA (  )  [static]

Returns the RWClassID of this class.

Reimplemented from RWSet.

Reimplemented in RWIdentityDictionary.

virtual void RWHashDictionary::clear (  )  [virtual]

Removes all key-value pairs in the collection.

Reimplemented from RWHashTable.

virtual void RWHashDictionary::clearAndDestroy (  )  [virtual]

Removes all key-value pairs in the collection, and deletes the key and the value.

Reimplemented from RWSet.

virtual RWCollectable* RWHashDictionary::find ( const RWCollectable target  )  const [virtual]

Returns the key which isEqual() to the object pointed to by target, or rwnil if no key was found.

Reimplemented from RWHashTable.

RWCollectable* RWHashDictionary::findKeyAndValue ( const RWCollectable target,
RWCollectable *&  v 
) const

Returns the key which isEqual() to the item pointed to by target, or rwnil if no key was found. The value is put in v. You are responsible for defining v before calling this function.

RWCollectable* RWHashDictionary::findValue ( const RWCollectable target,
RWCollectable newValue 
) const

Returns the value associated with the key which isEqual() to the item pointed to by target, or rwnil if no key was found. Replaces the value with newValue (if a key was found).

RWCollectable* RWHashDictionary::findValue ( const RWCollectable target  )  const

Returns the value associated with the key which isEqual() to the item pointed to by target, or rwnil if no key was found.

virtual RWCollectable* RWHashDictionary::insert ( RWCollectable c  )  [inline, private, virtual]

Adds c to the collection and returns it. If an item is already in the collection which isEqual() to c, then the existing item is returned and the new item is not inserted.

Reimplemented from RWSet.

RWCollectable* RWHashDictionary::insertKeyAndValue ( RWCollectable key,
RWCollectable value 
)

Adds a key-value pair to the collection and returns the key if successful, rwnil if the key is already in the collection.

virtual RWClassID RWHashDictionary::isA (  )  const [virtual]

Returns __RWHASHDICTIONARY.

Reimplemented from RWSet.

Reimplemented in RWIdentityDictionary.

virtual bool RWHashDictionary::isEqual ( const RWCollectable t  )  const [virtual]

Returns true if the collectable object "matches" the object at address t. The default definition is:

 return this == t;

i.e., both objects have the same address (a test for identity). The definition may be redefined in any consistent way.

Reimplemented from RWSet.

Reimplemented in RWIdentityDictionary.

virtual RWConstIterator* RWHashDictionary::newConstIterator (  )  const [virtual]

Returns a const pointer to a dynamically allocated iterator for the collection.

Reimplemented from RWSet.

virtual RWIterator* RWHashDictionary::newIterator (  )  [virtual]

Returns a dynamically allocated iterator for the collection.

Reimplemented from RWSet.

virtual RWCollectable* RWHashDictionary::newSpecies (  )  const [virtual]

Allocates a new object off the heap of the same type as self and returns a pointer to it. You are responsible for deleting the object when done with it.

Reimplemented from RWSet.

Reimplemented in RWIdentityDictionary.

bool RWHashDictionary::operator<= ( const RWHashTable t  )  const

Returns true if self is a subset of t, that is, every element of self has a counterpart in t which isEqual().

Reimplemented from RWSet.

Reimplemented in RWIdentityDictionary.

bool RWHashDictionary::operator<= ( const RWSet h  )  const

Returns true if self is a subset of h, that is, every element of self has a counterpart in h which isEqual().

Reimplemented from RWSet.

Reimplemented in RWIdentityDictionary.

bool RWHashDictionary::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.

Reimplemented in RWIdentityDictionary.

void RWHashDictionary::operator= ( RWHashDictionary &&  hd  )  [inline]

Move assignment. Self takes ownership of the data owned by hd.

Condition:
This method is only available on platforms with rvalue reference support.
void RWHashDictionary::operator= ( const RWHashDictionary hd  ) 

Assignment operator. Makes a shallow copy of the collection hd.

bool RWHashDictionary::operator== ( const RWHashTable t  )  const

Returns true if self and t have the same number of elements and if for every key in self there is a corresponding key in t which isEqual().

Reimplemented from RWHashTable.

bool RWHashDictionary::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.

virtual RWCollectable* RWHashDictionary::remove ( const RWCollectable target  )  [virtual]

Removes the key and value pair where the key isEqual() to the item pointed to by target. Returns the key, or rwnil if no match was found.

Reimplemented from RWHashTable.

virtual void RWHashDictionary::removeAndDestroy ( const RWCollectable target  )  [virtual]

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.

Reimplemented from RWCollection.

RWCollectable* RWHashDictionary::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 rwnil 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.

virtual RWCollection* RWHashDictionary::select ( RWtestCollectablePair  testfunc,
void *  x 
) const [virtual]

Evaluates the function pointed to by testfunc 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.

Reimplemented from RWCollection.

virtual RWCollection* RWHashDictionary::select ( RWtestCollectable  tst,
void *  x 
) const [virtual]

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.

Reimplemented from RWCollection.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.