Represents a group of ordered elements, as sorted by a comparison method, and allowing duplicates.
More...
#include <rw/bintree.h>
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.
- Synopsis
- Persistence
- Polymorphic
RWBinaryTree::RWBinaryTree |
( |
| ) |
|
Constructs an empty sorted collection.
Copy constructor. Constructs a shallow copy from t. Member function balance() is called before returning.
Move constructor. The constructed RWBinaryTree takes ownership of the data owned by bt.
- Condition:
- This method is available only on platforms with rvalue reference support.
virtual RWBinaryTree::~RWBinaryTree |
( |
| ) |
|
|
virtual |
Invokes the function pointer ap on each item in the collection, in order, from smallest to largest. The function pointed to by ap should take no action that could change the ordering of items in 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.
virtual void RWBinaryTree::clear |
( |
| ) |
|
|
virtual |
Removes all objects from the collection. Does not delete the objects themselves.
Implements RWCollection.
Returns a new, copy-constructed object of the same type as self. The caller is responsible for deleting the object.
Reimplemented from RWCollectable.
virtual size_t RWBinaryTree::entries |
( |
| ) |
const |
|
virtual |
Returns the total number of items in the collection.
Implements RWCollection.
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.
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 |
virtual bool RWBinaryTree::isEmpty |
( |
| ) |
const |
|
inlinevirtual |
Returns true
if the collection is empty, otherwise returns false
.
Implements RWCollection.
virtual bool RWBinaryTree::isEqual |
( |
const RWCollectable * |
t | ) |
const |
|
virtual |
Behaves as if compareTo(t) was invoked, returning true
if the result equals 0, false
otherwise.
Reimplemented from RWCollectable.
Returns a const pointer to a dynamically allocated iterator for the collection.
Implements RWCollection.
Returns a dynamically allocated iterator for the collection.
Implements RWCollection.
Returns a new, default-constructed object of the same type as self. The caller is responsible for deleting the object.
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.
Sets self to a shallow copy of bt.
Move assignment. Self takes ownership of the data owned by bt.
- Condition:
- This method is available only on platforms with rvalue reference support.
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.
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 |
( |
RWvostream & |
| ) |
const |
|
virtual |
Calls the global operator.
for each object in the collection.
Reimplemented from RWCollection.
virtual void RWBinaryTree::saveGuts |
( |
RWFile & |
| ) |
const |
|
virtual |
Calls the global operator:
for each object in the collection.
Reimplemented from RWCollection.
Swaps the data owned by self with the data owned by bt.