SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Represents a group of ordered elements, as sorted by a comparison method, and allowing duplicates. More...
#include <rw/bintree.h>
Public Member Functions | |
virtual RWCollectable * | newSpecies () const |
virtual RWClassID | isA () const |
RWBinaryTree () | |
RWBinaryTree (const RWBinaryTree &t) | |
RWBinaryTree (RWBinaryTree &&bt) | |
virtual | ~RWBinaryTree () |
void | operator= (const RWBinaryTree &bt) |
void | operator= (RWBinaryTree &&bt) |
bool | operator<= (const RWBinaryTree &bt) const |
bool | operator== (const RWBinaryTree &bt) const |
void | balance () |
size_t | 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 | isEmpty () const |
virtual bool | isEqual (const RWCollectable *a) const |
virtual size_t | occurrencesOf (const RWCollectable *target) const |
virtual RWCollectable * | remove (const RWCollectable *target) |
virtual void | saveGuts (RWvostream &) const |
virtual void | saveGuts (RWFile &) const |
virtual RWIterator * | newIterator () |
virtual RWConstIterator * | newConstIterator () const |
void | swap (RWBinaryTree &bt) |
Static Public Member Functions | |
static RWClassID | classIsA () |
Class RWBinaryTree represents a group of ordered elements, internally sorted by the compareTo() function. Duplicates are allowed. An object stored by an RWBinaryTree must inherit abstract base class RWCollectable.
typedef RWBinaryTree SortedCollection; // Smalltalk typedef. #include <rw/bintree.h> RWBinaryTree bt;
Polymorphic
RWBinaryTree::RWBinaryTree | ( | ) |
Constructs an empty sorted collection.
RWBinaryTree::RWBinaryTree | ( | const RWBinaryTree & | t | ) |
Copy constructor. Constructs a shallow copy from t. Member function balance() is called before returning.
RWBinaryTree::RWBinaryTree | ( | RWBinaryTree && | bt | ) |
Move constructor. The constructed RWBinaryTree takes ownership of the data owned by bt.
virtual RWBinaryTree::~RWBinaryTree | ( | ) | [virtual] |
Calls clear().
virtual void RWBinaryTree::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.
void RWBinaryTree::balance | ( | ) |
Special function to balance the tree. In a perfectly balanced binary tree with no duplicate elements, the number of nodes from the root to any external (leaf) node differs by at most one node. Since this collection allows duplicate elements, a perfectly balanced tree is not always possible. Preserves the order of duplicate elements.
static RWClassID RWBinaryTree::classIsA | ( | ) | [static] |
Returns the RWClassID of this class.
Reimplemented from RWCollectable.
virtual void RWBinaryTree::clear | ( | ) | [virtual] |
Removes all objects from the collection. Does not delete the objects themselves.
Implements RWCollection.
virtual size_t RWBinaryTree::entries | ( | ) | const [virtual] |
Returns the total number of items in the collection.
Implements RWCollection.
virtual RWCollectable* RWBinaryTree::find | ( | const RWCollectable * | target | ) | const [virtual] |
Returns the first item that compares equal to the item pointed to by target, or rwnil if no item was found.
Implements RWCollection.
size_t RWBinaryTree::height | ( | ) | const |
Returns the number of nodes between the root node and the farthest leaf. A RWBinaryTree with one entry will have a height of 1. Note that the entire tree is traversed to discover this value.
virtual RWCollectable* RWBinaryTree::insert | ( | RWCollectable * | c | ) | [virtual] |
Inserts the item c into the collection and returns it. Returns rwnil if the insertion was unsuccessful. The item c is inserted according to the value returned by compareTo(). insert() does not automatically balance the RWBinaryTree. Be careful not to call insert() on a long sequence of sorted items without also calling balance() since the result will be very unbalanced (and therefore inefficient).
Implements RWCollection.
virtual RWClassID RWBinaryTree::isA | ( | ) | const [virtual] |
Returns __RWBINARYTREE
.
Reimplemented from RWCollection.
virtual bool RWBinaryTree::isEmpty | ( | ) | const [inline, virtual] |
Returns true
if the collection is empty, otherwise returns false
.
Implements RWCollection.
virtual bool RWBinaryTree::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.
virtual RWConstIterator* RWBinaryTree::newConstIterator | ( | ) | const [virtual] |
Returns a const pointer to a dynamically allocated iterator for the collection.
Implements RWCollection.
virtual RWIterator* RWBinaryTree::newIterator | ( | ) | [virtual] |
Returns a dynamically allocated iterator for the collection.
Implements RWCollection.
virtual RWCollectable* RWBinaryTree::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.
virtual size_t RWBinaryTree::occurrencesOf | ( | const RWCollectable * | target | ) | const [virtual] |
Returns the number of items that compare equal to the item pointed to by target.
Implements RWCollection.
bool RWBinaryTree::operator<= | ( | const RWBinaryTree & | bt | ) | const |
Returns true
if self is a subset of the collection bt. That is, every item in self must compare equal to a unique item in bt.
void RWBinaryTree::operator= | ( | RWBinaryTree && | bt | ) |
Move assignment. Self takes ownership of the data owned by bt.
void RWBinaryTree::operator= | ( | const RWBinaryTree & | bt | ) |
Sets self to a shallow copy of bt.
bool RWBinaryTree::operator== | ( | const RWBinaryTree & | bt | ) | const |
Returns true
if self and bt are equivalent. That is, they must have the same number of items and every item in self must compare equal to a unique item in bt.
virtual RWCollectable* RWBinaryTree::remove | ( | const RWCollectable * | target | ) | [virtual] |
Removes the first item that compares equal to the object pointed to by target and returns it. Returns rwnil if no item was found.
Implements RWCollection.
virtual void RWBinaryTree::saveGuts | ( | RWFile & | ) | const [virtual] |
Calls the global operator:
RWFile& operator<<(RWFile&, const RWCollectable&);
for each object in the collection.
Reimplemented from RWCollection.
virtual void RWBinaryTree::saveGuts | ( | RWvostream & | ) | const [virtual] |
Calls the global operator.
RWvostream& operator<<(RWvostream&, const RWCollectable&);
for each object in the collection.
Reimplemented from RWCollection.
void RWBinaryTree::swap | ( | RWBinaryTree & | bt | ) |
Swaps the data owned by self with the data owned by bt.
© 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.