SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

A group of unordered elements, not accessible by an external key, where duplicates are not allowed. More...

#include <rw/rwset.h>

Inheritance diagram for RWSet:
RWHashTable RWCollection RWCollectable RWFactory RWHashDictionary RWIdentitySet RWIdentityDictionary

Public Member Functions

 RWSet ()
 
 RWSet (const RWSet &h)
 
 RWSet (RWSet &&h)
 
 RWSet (size_t n)
 
virtual ~RWSet ()
 
virtual void clearAndDestroy ()
 
virtual RWCollectablecopy () const
 
virtual RWCollectableinsert (RWCollectable *c)
 
void intersectWith (const RWSet &h, RWSet &ret) const
 
virtual RWClassID isA () const
 
virtual bool isEqual (const RWCollectable *) const
 
virtual RWConstIteratornewConstIterator () const
 
virtual RWIteratornewIterator ()
 
virtual RWCollectablenewSpecies () 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 void clear ()
 
virtual size_t entries () const
 
virtual RWCollectablefind (const RWCollectable *) 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 RWCollectableremove (const RWCollectable *)
 
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 removeAndDestroy (const RWCollectable *target)
 
virtual void restoreGuts (RWFile &)
 
virtual void restoreGuts (RWvistream &)
 
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 RWSetConstIterator
 
class RWSetIterator
 

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

Class RWSet represents a group of unordered elements, not accessible by an external key, where duplicates are not allowed. It corresponds to the Smalltalk class Set.

An object stored by RWSet must inherit from abstract base class RWCollectable, with suitable definition for virtual functions RWCollectable::hash() and RWCollectable::isEqual(). Use the function hash() to find objects with the same hash value, and then use isEqual() to confirm the match.

An item c is considered to be "already in the collection" if there is a member of the collection with the same hash value as c for which isEqual(c) returns true. In this case, method insert(c) will not add it, thus insuring that there are no duplicates.

The iterator for this class is RWSetIterator.

Synopsis
typedef RWSet Set; // Smalltalk typedef.
#include <rw/rwset.h>
A group of unordered elements, not accessible by an external key, where duplicates are not allowed.
Definition rwset.h:63
Persistence
Polymorphic

Constructor & Destructor Documentation

◆ RWSet() [1/4]

RWSet::RWSet ( )

Constructs an empty set with RWCollection::DEFAULT_CAPACITY hashing buckets.

◆ RWSet() [2/4]

RWSet::RWSet ( size_t n)

Constructs an empty set with n hashing buckets.

◆ RWSet() [3/4]

RWSet::RWSet ( const RWSet & h)
inline

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

◆ RWSet() [4/4]

RWSet::RWSet ( RWSet && h)
inline

Move constructor. The constructed RWSet takes ownership of the data owned by h.

Condition:
This method is available only on platforms with rvalue reference support.

◆ ~RWSet()

virtual RWSet::~RWSet ( )
virtual

Calls clear(), inherited from RWHashTable.

Member Function Documentation

◆ clearAndDestroy()

virtual void RWSet::clearAndDestroy ( )
virtual

Removes all objects from the collection and deletes them. Takes into account duplicate objects within a collection and only deletes them once. However, it does not take into account objects shared between different collections. Either do not use this function if you are sharing objects between separate collections, or put all collections that could be sharing objects into one single "super-collection" and call clearAndDestroy() on that.

Reimplemented from RWCollection.

Reimplemented in RWHashDictionary.

◆ copy()

virtual RWCollectable * RWSet::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 RWHashTable.

Reimplemented in RWHashDictionary, RWIdentityDictionary, and RWIdentitySet.

◆ insert()

virtual RWCollectable * RWSet::insert ( RWCollectable * c)
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.

Note
If self is a collection of key-value pairs (e.g. RWHashDictionary), this function throws std::bad_cast if c does not inherit from RWCollectableAssociation. If the collection does not contain an association with a key that "matches" the key of c, then a copy of the association is inserted and that association's key is returned. Otherwise, the insert fails by returning either rwnil or a pointer to the existing association's key.

Reimplemented from RWHashTable.

Reimplemented in RWHashDictionary, and RWIdentitySet.

◆ intersectWith()

void RWSet::intersectWith ( const RWSet & h,
RWSet & ret ) const

Computes the intersection of self and h, and inserts the result into ret (which may be either empty or not, depending on the effect desired). This function may be slightly more efficient than operator*=().

◆ isA()

virtual RWClassID RWSet::isA ( ) const
virtual

Returns __RWSET, i.e. a class identifier, that identifies this object's class.

Reimplemented from RWHashTable.

Reimplemented in RWHashDictionary, RWIdentityDictionary, and RWIdentitySet.

◆ isEqual()

virtual bool RWSet::isEqual ( const RWCollectable * t) const
virtual

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

Reimplemented from RWHashTable.

Reimplemented in RWHashDictionary, RWIdentityDictionary, and RWIdentitySet.

◆ newConstIterator()

virtual RWConstIterator * RWSet::newConstIterator ( ) const
virtual

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

Reimplemented from RWHashTable.

Reimplemented in RWHashDictionary.

◆ newIterator()

virtual RWIterator * RWSet::newIterator ( )
virtual

Returns a dynamically allocated iterator for the collection.

Reimplemented from RWHashTable.

Reimplemented in RWHashDictionary.

◆ newSpecies()

virtual RWCollectable * RWSet::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 RWHashTable.

Reimplemented in RWHashDictionary, RWIdentityDictionary, and RWIdentitySet.

◆ occurrencesOf()

virtual size_t RWSet::occurrencesOf ( const RWCollectable * target) const
virtual

Returns the count of entries that compare isEqual() to the item pointed to by target. Because duplicates are not allowed for this collection, only 0 or 1 can be returned.

Note
If self is a collection of key-value pairs (e.g. RWHashDictionary), this method compares target with the keys in the collection.

Reimplemented from RWHashTable.

◆ operator*=()

RWSet & RWSet::operator*= ( const RWSet & h)

Sets self to be the intersection of self and h. Returns self.

◆ operator<()

bool RWSet::operator< ( const RWSet & h) const

Returns true if self is a proper subset of h, that is, every element of self has a counterpart in h which isEqual(), but where the two sets are not identical.

◆ operator<=()

bool RWSet::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().

◆ operator=() [1/2]

RWSet & RWSet::operator= ( const RWSet & h)
inline

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

◆ operator=() [2/2]

RWSet & RWSet::operator= ( RWSet && h)
inline

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

Condition:
This method is available only on platforms with rvalue reference support.

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