SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Represents a group of ordered elements not accessible by an external key, and for which duplicates are not allowed. More...
#include <rw/btree.h>
Public Member Functions | |
virtual RWCollectable * | newSpecies () const |
virtual RWClassID | isA () const |
RWBTree () | |
virtual | ~RWBTree () |
RWBTree (const RWBTree &btr) | |
RWBTree (RWBTree &&btr) | |
void | operator= (const RWBTree &btr) |
void | operator= (RWBTree &&btr) |
bool | operator<= (const RWBTree &btr) const |
bool | operator== (const RWBTree &btr) const |
unsigned | height () const |
virtual void | apply (RWapplyCollectable ap, void *) |
virtual void | clear () |
virtual size_t | entries () const |
virtual RWCollectable * | find (const RWCollectable *target) const |
virtual RWCollectable * | insert (RWCollectable *c) |
virtual bool | isEqual (const RWCollectable *a) const |
virtual bool | isEmpty () const |
virtual size_t | occurrencesOf (const RWCollectable *target) const |
virtual RWCollectable * | remove (const RWCollectable *target) |
virtual RWIterator * | newIterator () |
virtual RWConstIterator * | newConstIterator () const |
void | swap (RWBTree &btr) |
Static Public Member Functions | |
static RWClassID | classIsA () |
Class RWBTree represents a group of ordered elements, not accessible by an external key. Duplicates are not allowed. An object stored by class RWBTree must inherit abstract base class RWCollectable. The elements are ordered internally according to the value returned by virtual function RWCollectable::compareTo().
This class has certain advantages over class RWBinaryTree. First, the B-tree is automatically balanced. (With class RWBinaryTree, you must call member function balance() explicitly to balance the tree.) 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 <rw/btree.h>
and recompiling. Larger values result in shallower trees, but less efficient use of memory.
Because many keys are held in a single node, class RWBTree also tends to fragment memory less.
#include <rw/btree.h> RWBTree a;
Polymorphic
RWBTree::RWBTree | ( | ) |
Constructs an empty B-tree.
virtual RWBTree::~RWBTree | ( | ) | [virtual] |
Calls clear().
RWBTree::RWBTree | ( | const RWBTree & | btr | ) |
Constructs self as a shallow copy of btr.
RWBTree::RWBTree | ( | RWBTree && | btr | ) |
Move constructor. The constructed RWBTree takes ownership of the data owned by btr.
virtual void RWBTree::apply | ( | RWapplyCollectable | ap, | |
void * | ||||
) | [virtual] |
Applies the user-supplied function pointed to by ap to each member of the collection, in order, from smallest to largest. This supplied function should not do anything to the items that could change the ordering of the collection.
Implements RWCollection.
static RWClassID RWBTree::classIsA | ( | ) | [static] |
Returns the RWClassID of this class.
Reimplemented from RWCollectable.
Reimplemented in RWBTreeDictionary.
virtual void RWBTree::clear | ( | ) | [virtual] |
Removes all objects from the collection. Does not delete the objects themselves.
Implements RWCollection.
Reimplemented in RWBTreeDictionary.
virtual size_t RWBTree::entries | ( | ) | const [virtual] |
Returns the total number of items in the collection.
Implements RWCollection.
virtual RWCollectable* RWBTree::find | ( | const RWCollectable * | target | ) | const [virtual] |
The first item that compares equal to the object pointed to by target is returned or rwnil if no item is found.
Implements RWCollection.
Reimplemented in RWBTreeDictionary.
unsigned RWBTree::height | ( | ) | const |
Returns the height of the tree, defined as the number of nodes traversed while descending from the root node to an external (leaf) node.
virtual RWCollectable* RWBTree::insert | ( | RWCollectable * | c | ) | [virtual] |
Inserts the item c into the collection and returns it. The item c is inserted according to the value returned by compareTo(). If an item is already in the collection that isEqual() to c, then the old item is returned and the new item is not inserted. Returns rwnil if the insertion was unsuccessful.
Implements RWCollection.
virtual RWClassID RWBTree::isA | ( | ) | const [virtual] |
virtual bool RWBTree::isEmpty | ( | ) | const [inline, virtual] |
Returns true
if the collection is empty, otherwise returns false
.
Implements RWCollection.
virtual bool RWBTree::isEqual | ( | const RWCollectable * | t | ) | const [virtual] |
Returns true
if the collectable object "matches" the object at address t. The default definition is:
return this == t;
i.e., both objects have the same address (a test for identity). The definition may be redefined in any consistent way.
Reimplemented from RWCollectable.
Reimplemented in RWBTreeDictionary.
virtual RWConstIterator* RWBTree::newConstIterator | ( | ) | const [inline, virtual] |
Returns rwnil
Implements RWCollection.
virtual RWIterator* RWBTree::newIterator | ( | ) | [inline, virtual] |
Returns rwnil
Implements RWCollection.
virtual RWCollectable* RWBTree::newSpecies | ( | ) | const [virtual] |
Allocates a new object off the heap of the same type as self and returns a pointer to it. You are responsible for deleting the object when done with it.
Reimplemented from RWCollectable.
Reimplemented in RWBTreeDictionary.
virtual size_t RWBTree::occurrencesOf | ( | const RWCollectable * | target | ) | const [virtual] |
Returns the number of items that compare equal to target. Since duplicates are not allowed, this function can only return 0 or 1.
Implements RWCollection.
bool RWBTree::operator<= | ( | const RWBTree & | btr | ) | const |
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.
void RWBTree::operator= | ( | RWBTree && | btr | ) |
Move assignment. Self takes ownership of the data owned by btr.
void RWBTree::operator= | ( | const RWBTree & | btr | ) |
Sets self to a shallow copy of btr.
bool RWBTree::operator== | ( | const RWBTree & | 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* RWBTree::remove | ( | const RWCollectable * | target | ) | [virtual] |
Removes and returns the first item that compares equal to the object pointed to by target. Returns rwnil if no item was found.
Implements RWCollection.
Reimplemented in RWBTreeDictionary.
void RWBTree::swap | ( | RWBTree & | btr | ) |
Swaps the data owned by self with the data owned by btr.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.