Tools.h++ Class Reference

Table Of Contents
Click on the banner to return to the Class Reference home page.
©Copyright 1996 Rogue Wave Software
RWBag
RWBag RWCollection RWCollectable
Synopsis
Description
Persistence
Public Constructors
Public Member Operators
Public Member Functions
Synopsis
typedef RWBag Bag; // Smalltalk typedef .
#include <rw/rwbag.h>
RWBag h;
Description
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 hash() and isEqual() (see class RWCollectable). 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.