SourcePro® 2023.1 |
SourcePro® API Reference Guide |
Corresponds to the Smalltalk class Bag, representing a group of unordered elements not accessible by an external key. More...
#include <rw/rwbag.h>
Public Member Functions | |
RWBag () | |
RWBag (size_t n) | |
RWBag (const RWBag &b) | |
RWBag (RWBag &&b) | |
virtual | ~RWBag () |
virtual void | apply (RWapplyCollectable ap, void *) |
size_t | buckets () const |
virtual void | clear () |
virtual void | clearAndDestroy () |
virtual RWCollectable * | copy () const |
virtual size_t | entries () const |
virtual RWCollectable * | find (const RWCollectable *target) const |
virtual RWCollectable * | insert (RWCollectable *c) |
RWCollectable * | insertWithOccurrences (RWCollectable *c, int n) |
virtual RWClassID | isA () const |
virtual bool | isEmpty () const |
virtual bool | isEqual (const RWCollectable *a) const |
virtual RWConstIterator * | newConstIterator () const |
virtual RWIterator * | newIterator () |
virtual RWCollectable * | newSpecies () const |
virtual size_t | occurrencesOf (const RWCollectable *target) const |
RWBag & | operator= (const RWBag &b) |
RWBag & | operator= (RWBag &&b) |
bool | operator== (const RWBag &b) const |
virtual RWCollectable * | remove (const RWCollectable *target) |
virtual void | removeAndDestroy (const RWCollectable *target) |
void | resize (size_t n=0) |
void | swap (RWBag &b) |
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 | restoreGuts (RWvistream &) |
virtual void | restoreGuts (RWFile &) |
virtual void | saveGuts (RWvostream &) const |
virtual void | saveGuts (RWFile &) const |
RWCollection * | select (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 |
Static Public Member Functions | |
static RWClassID | classIsA () |
Static Public Member Functions inherited from RWCollectable | |
static RWClassID | classID (const RWStringID &name) |
static RWClassID | classIsA () |
static bool | isAtom (RWClassID id) |
static RWspace | nilStoreSize () |
Additional Inherited Members | |
Static Public Attributes inherited from RWCollection | |
static size_t | DEFAULT_CAPACITY |
Related Functions inherited from RWCollection | |
typedef void(* | RWapplyCollectable) (RWCollectable *, void *) |
typedef bool(* | RWtestCollectable) (const RWCollectable *, const void *) |
typedef bool(* | RWtestCollectablePair) (const RWCollectable *, const RWCollectable *, const void *) |
Class RWBag corresponds to the Smalltalk class Bag. It represents a group of unordered elements, not accessible by an external key. Duplicates are allowed.
An object stored by RWBag must inherit abstract base class RWCollectable, with suitable definition for virtual functions RWCollectable::hash() and RWCollectable::isEqual(). The function hash() is used to find objects with the same hash value, then isEqual() is used to confirm the match.
Class RWBag is implemented by using an internal hashed dictionary (RWHashDictionary) which keeps track of the number of occurrences of an item. If an item is added to the collection that compares equal (isEqual()) to an existing item in the collection, then the count is incremented. Note that this means that only the first instance of a value is actually inserted: subsequent instances cause the occurrence count to be incremented. This behavior parallels the Smalltalk implementation of Bag.
Member function apply() and the iterator are called repeatedly according to the count for an item.
See class RWHashTable if you want duplicates to be stored, rather than merely counted.
RWBag::RWBag | ( | ) |
Constructs an empty bag with RWCollection::DEFAULT_CAPACITY buckets.
RWBag::RWBag | ( | size_t | n | ) |
Constructs an empty bag with n buckets.
RWBag::RWBag | ( | const RWBag & | b | ) |
Copy constructor. Makes a shallow copy of b.
RWBag::RWBag | ( | RWBag && | b | ) |
Move constructor. The constructed RWBag takes ownership of the data owned by b.
|
virtual |
Calls the clear() method.
|
virtual |
Invokes the function pointer ap on each item in the collection in a generally unpredictable order. If an item has been inserted more than once (i.e., more than one item isEqual()), then apply() will be called that many times. The function pointed to by ap should take no action that could change the hash value or the meaning of isEqual() for the items.
Implements RWCollection.
|
inline |
Returns the current number of buckets allocated to the internal hash table.
|
virtual |
Removes all objects from the collection. Does not delete the objects themselves.
Implements RWCollection.
|
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.
|
virtual |
Returns a new, copy-constructed object of the same type as self. The caller is responsible for deleting the object.
Reimplemented from RWCollectable.
|
inlinevirtual |
Returns the total number of items in the collection.
Implements RWCollection.
|
virtual |
The first item that was inserted into the Bag
and which equals target is returned, or rwnil if no item is found. Hashing is used to narrow the search.
Implements RWCollection.
|
virtual |
Inserts the item c into the collection and returns it, or if an item was already in the collection that isEqual() to c, returns the old item and increments its count.
Implements RWCollection.
RWCollectable* RWBag::insertWithOccurrences | ( | RWCollectable * | c, |
int | n | ||
) |
Inserts the item c into the collection with count n and returns it, or if an item was already in the collection that isEqual() to c, then returns the old item and increments its count by n.
|
virtual |
Returns the unique id for RWBag.
Reimplemented from RWCollection.
|
inlinevirtual |
Returns true
if the collection is empty, otherwise returns false
.
Implements RWCollection.
|
virtual |
Behaves as if compareTo(t) was invoked, returning true
if the result equals 0, false
otherwise.
Reimplemented from RWCollectable.
|
virtual |
Returns a const pointer to a dynamically allocated iterator for the collection.
Implements RWCollection.
|
virtual |
Returns a dynamically allocated iterator for the collection.
Implements RWCollection.
|
virtual |
Returns a new, default-constructed object of the same type as self. The caller is responsible for deleting the object.
Reimplemented from RWCollectable.
|
virtual |
Returns the number of items that are equal to the item pointed to by target.
Implements RWCollection.
Move assignment. Self takes ownership of the data owned by b.
bool RWBag::operator== | ( | const RWBag & | b | ) | const |
Returns true
if self and bag b have the same number of total entries and if for every key in self there is a corresponding key in b which isEqual() and which has the same number of entries.
|
virtual |
Removes and returns the item that isEqual() to the item pointed to by target. Returns rwnil if no item was found.
Implements RWCollection.
|
virtual |
Removes the item that isEqual() to the item pointed to by target. Destroys the item as well if it is the last occurrence in the collection.
Reimplemented from RWCollection.
void RWBag::resize | ( | size_t | n = 0 | ) |
Resizes the internal hash table to have n buckets. The overhead for this function is the hashing of every element in the collection. If n is zero, then an appropriate size is picked automatically.
void RWBag::swap | ( | RWBag & | b | ) |
Swaps the data owned by self with the data owned by b.
Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |