SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 (const RWHashDictionary &hd)
 
 RWHashDictionary (RWHashDictionary &&hd)
 
 RWHashDictionary (size_t n)
 
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 (const RWSet &h)
 
 RWSet (RWSet &&h)
 
 RWSet (size_t n)
 
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 (const RWHashTable &t)
 
 RWHashTable (RWHashTable &&t)
 
 RWHashTable (size_t N)
 
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 (RWFile &) const
 
virtual void saveGuts (RWvostream &) 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
 

Friends

class RWHashDictionaryIterator
 

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>
Represents a group of unordered values, accessible by external keys.
Definition hashdict.h:48
Persistence
Polymorphic

Constructor & Destructor Documentation

◆ RWHashDictionary() [1/4]

RWHashDictionary::RWHashDictionary ( )

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

◆ RWHashDictionary() [2/4]

RWHashDictionary::RWHashDictionary ( size_t n)

Constructs an empty hashed dictionary using n hashing buckets.

◆ RWHashDictionary() [3/4]

RWHashDictionary::RWHashDictionary ( const RWHashDictionary & hd)

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

◆ RWHashDictionary() [4/4]

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.

◆ ~RWHashDictionary()

virtual RWHashDictionary::~RWHashDictionary ( )
virtual

Calls clear().

Member Function Documentation

◆ applyToKeyAndValue()

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.

◆ clear()

virtual void RWHashDictionary::clear ( )
virtual

Removes all key-value pairs in the collection.

Reimplemented from RWHashTable.

◆ clearAndDestroy()

virtual void RWHashDictionary::clearAndDestroy ( )
virtual

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

Reimplemented from RWSet.

◆ copy()

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.

◆ find()

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.

◆ findKeyAndValue()

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.

◆ findValue() [1/2]

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.

◆ findValue() [2/2]

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

◆ insert()

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.

◆ insertKeyAndValue()

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.

◆ isA()

virtual RWClassID RWHashDictionary::isA ( ) const
virtual

Returns __RWHASHDICTIONARY.

Reimplemented from RWSet.

Reimplemented in RWIdentityDictionary.

◆ isEqual()

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.

◆ newConstIterator()

virtual RWConstIterator * RWHashDictionary::newConstIterator ( ) const
virtual

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

Reimplemented from RWSet.

◆ newIterator()

virtual RWIterator * RWHashDictionary::newIterator ( )
virtual

Returns a dynamically allocated iterator for the collection.

Reimplemented from RWSet.

◆ newSpecies()

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.

◆ operator<=()

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.

◆ operator=() [1/2]

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

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

◆ operator=() [2/2]

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.

◆ operator==()

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.

◆ remove()

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.

◆ removeAndDestroy()

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.

◆ removeKeyAndValue()

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.

◆ restoreGuts() [1/2]

virtual void RWHashDictionary::restoreGuts ( RWFile & )
virtual

Repeatedly calls the global operator:

RWFile& operator>>(RWFile&, RWCollectable*&);
Contains virtual functions for identifying, hashing, comparing, storing and retrieving collectable ob...
Definition collect.h:441
Represents an abstraction of a filesystem regular file.
Definition rwfile.h:68

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

Reimplemented from RWCollection.

◆ restoreGuts() [2/2]

virtual void RWHashDictionary::restoreGuts ( RWvistream & )
virtual

Repeatedly calls the global operator:

Abstract base class providing an interface for format-independent retrieval of fundamental types and ...
Definition vstream.h:244

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

Reimplemented from RWCollection.

◆ select() [1/2]

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.

◆ select() [2/2]

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 © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.