SourcePro® API Reference Guide

 
List of all members | Public Member Functions
RWHashDictionary Class Reference

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

#include <rw/hashdict.h>

Inheritance diagram for RWHashDictionary:
RWSet RWHashTable RWCollection RWCollectable RWIdentityDictionary

Public Member Functions

 RWHashDictionary ()
 
 RWHashDictionary (size_t n)
 
 RWHashDictionary (const RWHashDictionary &hd)
 
 RWHashDictionary (RWHashDictionary &&hd)
 
virtual ~RWHashDictionary ()
 
void applyToKeyAndValue (RWapplyKeyAndValue ap, void *x)
 
virtual void clear ()
 
virtual void clearAndDestroy ()
 
virtual RWCollectablecopy () const
 
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
 
virtual RWCollectableinsert (RWCollectable *a)
 
RWCollectableinsertKeyAndValue (RWCollectable *key, RWCollectable *value)
 
virtual RWClassID isA () const
 
virtual bool isEqual (const RWCollectable *) const
 
virtual RWConstIteratornewConstIterator () const
 
virtual RWIteratornewIterator ()
 
virtual RWCollectablenewSpecies () const
 
bool operator<= (const RWHashDictionary &hd) const
 
RWHashDictionaryoperator= (const RWHashDictionary &hd)
 
RWHashDictionaryoperator= (RWHashDictionary &&hd)
 
bool operator== (const RWHashDictionary &hd) const
 
virtual RWCollectableremove (const RWCollectable *target)
 
virtual void removeAndDestroy (const RWCollectable *target)
 
RWCollectableremoveKeyAndValue (const RWCollectable *target, RWCollectable *&v)
 
virtual void restoreGuts (RWFile &)
 
virtual void restoreGuts (RWvistream &)
 
virtual RWCollectionselect (RWtestCollectable tst, void *x) const
 
virtual RWCollectionselect (RWtestCollectablePair testfunc, void *x) const
 
- Public Member Functions inherited from RWSet
 RWSet ()
 
 RWSet (size_t n)
 
 RWSet (const RWSet &h)
 
 RWSet (RWSet &&h)
 
virtual ~RWSet ()
 
void intersectWith (const RWSet &h, RWSet &ret) const
 
virtual size_t occurrencesOf (const RWCollectable *target) const
 
RWSetoperator*= (const RWSet &h)
 
bool operator< (const RWSet &h) const
 
bool operator<= (const RWSet &h) const
 
RWSetoperator= (const RWSet &h)
 
RWSetoperator= (RWSet &&h)
 
- Public Member Functions inherited from RWHashTable
 RWHashTable ()
 
 RWHashTable (size_t N)
 
 RWHashTable (const RWHashTable &t)
 
 RWHashTable (RWHashTable &&t)
 
virtual void apply (RWapplyCollectable ap, void *)
 
virtual size_t entries () const
 
virtual bool isEmpty () const
 
bool operator!= (const RWHashTable &) const
 
bool operator<= (const RWHashTable &t) const
 
RWHashTableoperator= (const RWHashTable &t)
 
RWHashTableoperator= (RWHashTable &&t)
 
bool operator== (const RWHashTable &t) const
 
virtual void resize (size_t n=0)
 
void swap (RWHashTable &t)
 
- Public Member Functions inherited from RWCollection
virtual ~RWCollection ()
 
RWBag asBag () const
 
RWBinaryTree asBinaryTree () const
 
RWOrdered asOrderedCollection () const
 
RWSet asSet () const
 
RWBinaryTree asSortedCollection () const
 
virtual RWspace binaryStoreSize () const
 
virtual bool contains (const RWCollectable *target) const
 
void operator+= (const RWCollection &c)
 
void operator-= (const RWCollection &c)
 
virtual void saveGuts (RWvostream &) const
 
virtual void saveGuts (RWFile &) const
 
RWCollectionselect (RWtestCollectable tst, void *vp) const
 
- Public Member Functions inherited from RWCollectable
virtual ~RWCollectable ()
 
virtual int compareTo (const RWCollectable *) const
 
virtual unsigned hash () const
 
RWspace recursiveStoreSize () const
 
RWStringID stringID () const
 

Additional Inherited Members

- Static Public Member Functions inherited from RWCollectable
static RWClassID classID (const RWStringID &name)
 
static RWClassID classIsA ()
 
static bool isAtom (RWClassID id)
 
static RWspace nilStoreSize ()
 
- Static Public Attributes inherited from RWCollection
static size_t DEFAULT_CAPACITY
 

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>
Persistence
Polymorphic

Constructor & Destructor Documentation

RWHashDictionary::RWHashDictionary ( )

Constructs an empty hashed dictionary using RWCollection::DEFAULT_CAPACITY hashing buckets.

RWHashDictionary::RWHashDictionary ( size_t  n)

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 available only on platforms with rvalue reference support.
virtual RWHashDictionary::~RWHashDictionary ( )
virtual

Calls clear().

Member Function Documentation

void RWHashDictionary::applyToKeyAndValue ( RWapplyKeyAndValue  ap,
void *  x 
)

Invokes the function pointer ap on each key-value pair in the collection. Pairs are not visited in any particular order. An untyped argument may be passed to the ap function through x.

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::copy ( ) const
virtual

Returns a new, copy-constructed object of the same type as self. The caller is responsible for deleting the object.

Reimplemented from RWSet.

Reimplemented in RWIdentityDictionary.

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) const

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

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

virtual RWCollectable* RWHashDictionary::insert ( RWCollectable a)
virtual

Adds a copy of the RWCollectableAssociation a to the collection and returns its key. If an item in the collection already has a key which isEqual() to a, then rwnil is returned and the item is not inserted.

Note
If a is not an RWCollectableAssociation, this function throws std::bad_cast.

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

Behaves as if compareTo(t) was invoked, returning true if the result equals 0, false otherwise.

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

Returns a new, default-constructed object of the same type as self. The caller is responsible for deleting the object.

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.

RWHashDictionary& RWHashDictionary::operator= ( const RWHashDictionary hd)

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

RWHashDictionary& RWHashDictionary::operator= ( RWHashDictionary &&  hd)
inline

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

Condition:
This method is available only on platforms with rvalue reference support.
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 void RWHashDictionary::restoreGuts ( RWFile )
virtual

Repeatedly calls the global operator:

RWFile& operator>>(RWFile&, RWCollectable*&);

followed by insert(RWCollectable*) for each item in the collection.

Reimplemented from RWCollection.

virtual void RWHashDictionary::restoreGuts ( RWvistream )
virtual

Repeatedly calls the global operator:

followed by insert(RWCollectable*) for each item in the collection.

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.

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.

Copyright © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.