Class ABinaryTreeIterator

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ABinaryTreeIterator = class(AnIterator)

Description

Instances of this class can be used to iterate through the nodes in ABinaryTree and its descendants, starting with the root node and proceeding toward ABinaryTree.YoungestNode.

Nodes may be added and removed from the tree while the iterator is in use; the changes will be reflected by the iterator. The obvious exception to this rule is that the node represented by ABinaryTreeIterator.Current cannot be deleted until the iterator passes over it without causing program crashes. Likewise, the node directly attached to ABinaryTreeIterator.Current cannot be deleted or removed while ABinaryTreeIterator.next is operating (say, from a different thread). This is because we do not use reference counting or any other garbage collection routine to prevent the node from being deleted while the iterator is processing it. It is the responsibility of the programmer to know how program memory is being managed.

Hierarchy

Overview

Fields

Protected MyCurrentNode: ABinaryLeaf;
Protected MyTree: ABinaryTree;

Methods

Public constructor over(const ThisTree: ABinaryTree); virtual;
Public function init: boolean; override;
Public function continues: boolean; override;
Public procedure next; override;
Public function shallowCopyFrom(const Other: AnObject): boolean; override;
Public function Current: ABinaryLeaf; virtual;
Public function Tree: ABinaryTree; virtual;

Description

Fields

Protected MyCurrentNode: ABinaryLeaf;

Refers to the current node being processed

Protected MyTree: ABinaryTree;

Refers to the tree being processed

Methods

Public constructor over(const ThisTree: ABinaryTree); virtual;

Construct an instance of ABinaryTreeIterator that will iterate over the nodes in ThisTree.

This method is called automatically by ABinaryTree.iterator, which is the preferred method for obtaining an instance of this class.

Public function init: boolean; override;

Initializer

Public function continues: boolean; override;

Determine whether or not there are more nodes over which to iterate. For more information on this routine, see AnIterator.continues.

Public procedure next; override;

Retrieve the next node from the tree being processed.

If there are no more nodes (the iterator has reached the end of the tree), then this routine does nothing.

Public function shallowCopyFrom(const Other: AnObject): boolean; override;

Construct a shallow copy of the other object.

This method overrides the behavior inherited from AnObject.shallowCopyFrom: it calls that method, then checks to see whether Other is an instance of ABinaryTreeIterator. If so, it copies the values of

from Other to Self, overwriting the values in Self.

Public function Current: ABinaryLeaf; virtual;

Retrieve a reference to the most recent node retrieved from the tree.

The reference returned by this routine can be cast to a descendant of ABinaryLeaf if appropriate. The caller should know what type of node exists within the tree being processed.

The reference returned by this routine should NOT be freed by the caller.

Public function Tree: ABinaryTree; virtual;

Retrieve a reference to the tree being processed.

The reference returned by this routine can be cast to a descendant of ABinaryTree if appropriate. The caller should know what type of tree is being processed by the iterator.

The reference returned by this routine should NOT be freed by the caller.


Generated by PasDoc 0.13.0 on 2015-01-10 17:13:18