SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Static Public Member Functions
RWBTreeDictionary Class Reference

Represents a dictionary for the storage and retrieval of key-value pairs, and implemented as a B-tree. More...

#include <rw/btrdict.h>

Inheritance diagram for RWBTreeDictionary:
RWBTree RWCollection RWCollectable

Public Member Functions

 RWBTreeDictionary ()
 
 RWBTreeDictionary (const RWBTreeDictionary &btr)
 
 RWBTreeDictionary (RWBTreeDictionary &&btr)
 
virtual ~RWBTreeDictionary ()
 
void applyToKeyAndValue (RWapplyKeyAndValue ap, void *)
 
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 *a) const
 
virtual RWCollectablenewSpecies () const
 
bool operator<= (const RWBTreeDictionary &btr) const
 
RWBTreeDictionaryoperator= (const RWBTreeDictionary &btr)
 
RWBTreeDictionaryoperator= (RWBTreeDictionary &&btr)
 
bool operator== (const RWBTreeDictionary &btr) 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 &)
 
RWCollectionselect (RWtestCollectable testfunc, void *x) const
 
RWCollectionselect (RWtestCollectablePair testfunc, void *x) const
 
- Public Member Functions inherited from RWBTree
 RWBTree ()
 
 RWBTree (const RWBTree &btr)
 
 RWBTree (RWBTree &&btr)
 
virtual ~RWBTree ()
 
virtual void apply (RWapplyCollectable ap, void *)
 
virtual size_t entries () const
 
unsigned height () const
 
virtual bool isEmpty () const
 
virtual RWConstIteratornewConstIterator () const
 
virtual RWIteratornewIterator ()
 
virtual size_t occurrencesOf (const RWCollectable *target) const
 
bool operator<= (const RWBTree &btr) const
 
RWBTreeoperator= (const RWBTree &btr)
 
RWBTreeoperator= (RWBTree &&btr)
 
bool operator== (const RWBTree &btr) const
 
void swap (RWBTree &btr)
 
- 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 (RWvostream &) const
 
virtual void saveGuts (RWFile &) 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
 

Static Public Member Functions

static RWClassID classIsA ()
 
- Static Public Member Functions inherited from RWBTree
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
 

Detailed Description

Dictionary class implemented as a B-tree, for the storage and retrieval of key-value pairs. Both the keys and values must inherit abstract base class RWCollectable. The elements are ordered internally according to the value returned by virtual function RWCollectable::compareTo() of the keys. Duplicate keys are not allowed.

The B-tree is balanced. That is, nodes are never allowed to have less than a certain number of items (called the order). The default order is 50, but may be changed by resetting the value of the static constant order in the header file <btree.h> and recompiling. Larger values result in shallower trees, but less efficient use of memory.

Synopsis
#include <rw/btrdict.h>
Persistence
Polymorphic

Constructor & Destructor Documentation

RWBTreeDictionary::RWBTreeDictionary ( )

Constructs an empty B-tree dictionary.

RWBTreeDictionary::RWBTreeDictionary ( const RWBTreeDictionary btr)

Constructs self as a shallow copy of btr.

RWBTreeDictionary::RWBTreeDictionary ( RWBTreeDictionary &&  btr)
inline

Move constructor. The constructed RWBTreeDictionary takes ownership of the data owned by btr.

Condition:
This method is available only on platforms with rvalue reference support.
virtual RWBTreeDictionary::~RWBTreeDictionary ( )
virtual

Calls clear().

Member Function Documentation

void RWBTreeDictionary::applyToKeyAndValue ( RWapplyKeyAndValue  ap,
void *   
)

Invokes the function pointer ap on each key-value pair in the collection, in order, from smallest to largest.

static RWClassID RWBTreeDictionary::classIsA ( )
static

Returns the RWClassID of this class.

virtual void RWBTreeDictionary::clear ( )
virtual

Removes all key-value pairs from the collection.

Reimplemented from RWBTree.

virtual void RWBTreeDictionary::clearAndDestroy ( )
virtual

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

Reimplemented from RWCollection.

virtual RWCollectable* RWBTreeDictionary::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 RWBTree.

virtual RWCollectable* RWBTreeDictionary::find ( const RWCollectable target) const
virtual

Returns the key in the collection that compares equal to the object pointed to by target, or rwnil if no key is found.

Reimplemented from RWBTree.

RWCollectable* RWBTreeDictionary::findKeyAndValue ( const RWCollectable target,
RWCollectable *&  v 
) const

Returns the key in the collection that compares equal to the object 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.

RWCollectable* RWBTreeDictionary::findValue ( const RWCollectable target) const

Returns the value associated with the key that compares equal to the object pointed to by target, or rwnil if no key was found.

RWCollectable* RWBTreeDictionary::findValue ( const RWCollectable target,
RWCollectable newValue 
) const

Returns the value associated with the key that compares equal to the object pointed to by target, or rwnil if no key was found. Replaces the value with newValue (if a key was found).

virtual RWCollectable* RWBTreeDictionary::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 RWBTree.

RWCollectable* RWBTreeDictionary::insertKeyAndValue ( RWCollectable key,
RWCollectable value 
)

Adds a key-value pair to the collection and returns the key if successful, or rwnil if the key is already in the collection.

virtual RWClassID RWBTreeDictionary::isA ( ) const
virtual

Returns __RWBTREEDICTIONARY.

Reimplemented from RWBTree.

virtual bool RWBTreeDictionary::isEqual ( const RWCollectable t) const
virtual

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

Reimplemented from RWBTree.

virtual RWCollectable* RWBTreeDictionary::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 RWBTree.

bool RWBTreeDictionary::operator<= ( const RWBTreeDictionary btr) const
inline

Returns true if self is a subset of btr. That is, for every item in self, there must be an item in btr that compares equal. Normally this method is inherited from RWBTree.

RWBTreeDictionary& RWBTreeDictionary::operator= ( const RWBTreeDictionary btr)

Sets self to a shallow copy of btr.

RWBTreeDictionary& RWBTreeDictionary::operator= ( RWBTreeDictionary &&  btr)
inline

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

Condition:
This method is available only on platforms with rvalue reference support.
bool RWBTreeDictionary::operator== ( const RWBTreeDictionary btr) const

Returns true if self and btr are equivalent. That is, they must have the same number of items and for every item in self, there must be an item in btr that compares equal.

virtual RWCollectable* RWBTreeDictionary::remove ( const RWCollectable target)
virtual

Removes the key-value pair for which the key compares equal to the object pointed to by target. Returns the key, or rwnil if no match was found.

Reimplemented from RWBTree.

virtual void RWBTreeDictionary::removeAndDestroy ( const RWCollectable target)
virtual

Removes and deletes the key-value pair for which the key compares equal to the object 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.

RWCollectable* RWBTreeDictionary::removeKeyAndValue ( const RWCollectable target,
RWCollectable *&  v 
)

Removes the key-value pair for which the key compares equal to the object pointed to by target. Returns the key, or rwnil if no match was found. The value is put in v. You are responsible for defining v before calling this function.

virtual void RWBTreeDictionary::restoreGuts ( RWFile )
virtual

Repeatedly calls the global operator:

RWFile& operator>>(RWFile&, RWCollectable*&);

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

Reimplemented from RWCollection.

virtual void RWBTreeDictionary::restoreGuts ( RWvistream )
virtual

Repeatedly calls the global operator:

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

Reimplemented from RWCollection.

RWCollection* RWBTreeDictionary::select ( RWtestCollectable  testfunc,
void *  x 
) const

Evaluates the function pointed to by testfunc for the key of each item in the RWBTreeDictionary. It inserts keys and values for which the function returns true into a new RWBTreeDictionary 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 not a virtual function.

RWCollection* RWBTreeDictionary::select ( RWtestCollectablePair  testfunc,
void *  x 
) const

Evaluates the function pointed to by testfunc for both the key and the value of each item in the RWBTreeDictionary. It inserts keys and values for which the function returns true into a new RWBTreeDictionary 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 not a virtual function.

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