Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWBag


RWBag-->RWCollection-->RWCollectable

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

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.

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.

Persistence

Polymorphic

Public Constructors

RWBag(size_t n = RWDEFAULT_CAPACITY);
RWBag(const RWBag& b);

Public Member Operators

void
operator=(const RWBag& b);
RWBoolean
operator==(const RWBag& b) const;

Public Member Functions

virtual void 
apply(RWapplyCollectable ap, void*);
virtual RWspace 
binaryStoreSize() const;
virtual void
clear();
virtual void
clearAndDestroy();
virtual int
compareTo(const RWCollectable* a) const;
virtual RWBoolean
contains(const RWCollectable* target) const;
virtual size_t
entries() const;
virtual RWCollectable*
find(const RWCollectable* target) const;
virtual unsigned
hash() const;
virtual RWCollectable*
insert(RWCollectable* c);
RWCollectable*
insertWithOccurrences(RWCollectable* c,size_t n);
virtual RWClassID
isA() const;
virtual RWBoolean
isEmpty() const;
virtual RWBoolean
isEqual(const RWCollectable* a) const;
virtual size_t
occurrencesOf(const RWCollectable* target) const;
virtual RWCollectable*
remove(const RWCollectable* target);
virtual void
removeAndDestroy(const RWCollectable* target);
void
resize(size_t n = 0);
virtual void
restoreGuts(RWvistream&);
virtual void
restoreGuts(RWFile&);
virtual void
saveGuts(RWvostream&) const;
virtual void
saveGuts(RWFile&) const;
RWStringID
stringID();


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.