Class Tree

Description

The Tree data structure used by the Hierarchy.

  • since: Created: 8/30/2003
  • version: $Id: Tree.class.php,v 1.16 2007/09/04 20:25:42 adamfranco Exp $
  • license: GNU General Public License (GPL)
  • copyright: Copyright © 2005, Middlebury College

Located in /harmoni/core/oki2/hierarchy/tree/Tree.class.php (line 17)

TreeInterface
   |
   --Tree
Variable Summary
array $_nodes
integer $_size
Method Summary
Tree Tree ()
void addNode (ref $node, optional $parent, [optional $clearTraversal = false])
void clearTraversalCaches (object Node $node, boolean $down)
void clearTraverseDownCaches (object Node $node)
void clearTraverseUpCaches (object Node $node)
void deleteNode (object node $node, [mixed $clearTraversal = false])
string getCacheKey (object Node $node, boolean $down, integer $levels)
ref getNode (mixed $id)
ref getNodes ()
integer getSize ()
boolean nodeExists (mixed $id)
ref traverse (ref $node, boolean $down, integer $levels)
ref _traverse (ref &$result, ref $node, boolean $down, integer $levels, integer $startingLevel, [string $initiatingNodeId = null])
Variables
array $_nodes (line 27)

The nodes of this tree. This is an array of node object. The indices of the array correspond to the node id.

  • var: _nodes
  • access: private
integer $_size (line 35)

The size of this tree.

  • var: _size
  • access: private
Methods
Constructor Tree (line 42)

The constructor does some initializations.

  • access: public
Tree Tree ()
addNode (line 60)

Adds the specified node to the tree and makes it a child of the specified parent. If the parent is not specified, then it makes the node a root. Always use this method instead of the addChild() method of the individual tree nodes.

  • access: public
void addNode (ref $node, optional $parent, [optional $clearTraversal = false])
  • ref $node: object The node to add.
  • optional $parent: ref object parent The node that will become the parent of the added node.
  • optional $clearTraversal: boolean $clearTraversal If true, the tree will clear its traversal cache. This is needed when changing parentage.

Redefinition of:
TreeInterface::addNode()
Adds the specified node to the hierarchy and makes it a child of the specified parent. If the parent is not specified, then it makes the node a root.
clearTraversalCaches (line 298)

Clear the traverse caches for the given node and direction

  • since: 11/9/05
  • access: public
void clearTraversalCaches (object Node $node, boolean $down)
  • object Node $node
  • boolean $down
clearTraverseDownCaches (line 281)

Clear the traverse down caches for the given node and all of its ancestors

  • since: 11/9/05
  • access: public
void clearTraverseDownCaches (object Node $node)
  • object Node $node
clearTraverseUpCaches (line 265)

Clear the traverse up caches for the given node and all of its decendents

  • since: 11/9/05
  • access: public
void clearTraverseUpCaches (object Node $node)
  • object Node $node
deleteNode (line 118)

Delete the node from the tree. This can only be done if the node has no parents and no children.

  • access: public
void deleteNode (object node $node, [mixed $clearTraversal = false])
  • object node $node: The node to delete.

Redefinition of:
TreeInterface::deleteNode()
Delete the node from the tree. This can only be done if the node has no parents and no children.
getCacheKey (line 318)

Answer the traversal cacheKey for this node, direction, and levels

  • since: 11/9/05
  • access: public
string getCacheKey (object Node $node, boolean $down, integer $levels)
  • object Node $node
  • boolean $down
  • integer $levels
getNode (line 173)

Returns the node with the specified id. If it does not exist, return

  1. null
.

  • return: object The requested node.
    1. Null
    , if the node is not in the tree.
  • access: public
ref getNode (mixed $id)
  • mixed $id: id The id of the requested node.

Redefinition of:
TreeInterface::getNode()
Returns the node with the specified id. If it does not exist, return
  1. null
.
getNodes (line 211)

Simply returns all nodes of this tree in an array in no particular order.

  • return: array An array of all nodes.
  • access: public
ref getNodes ()
getSize (line 161)

Returns the size (number of nodes) in this tree.

  • return: The size (number of nodes) in this tree.
  • access: public
integer getSize ()

Redefinition of:
TreeInterface::getSize()
Returns the size (number of nodes) in this hierarchy.
nodeExists (line 192)

Returns

  1. true
if the node with the specified id (string) exists.

  • return:
    1. true
    if the node with the specified id is in the tree; else
    1. false
    .
  • access: public
boolean nodeExists (mixed $id)
  • mixed $id: id The id of the node.

Redefinition of:
TreeInterface::nodeExists()
Returns
  1. true
if the node with the specified id (string) exists.
traverse (line 233)

Traverses the tree and returns all the nodes in an array. The traversal is a depth-first pre-order traversal starting from the specified node.

  • return: array An array of all nodes in the tree visited in a pre-order manner. The keys of the array correspond to the nodes' ids. Each element of the array is another array of two elements, the first being the node itself, and the second being the depth of the node relative to the starting node. Descendants are assigned increasingly positive levels; ancestors increasingly negative levels.
  • access: public
ref traverse (ref $node, boolean $down, integer $levels)
  • ref $node: object node The node to start traversal from.
  • boolean $down: down If
    1. true
    , this argument specifies that the traversal will go down the children; if
    1. false
    then it will go up the parents.
  • integer $levels: levels Specifies how many levels of nodes remain to be fetched. This will be recursively decremented and at 0 the recursion will stop. If this is negative then the recursion will go on until the last level is processed.

Redefinition of:
TreeInterface::traverse()
Traverses the hierarchy and returns all the nodes in an array. The traversal is a pre-order traversal starting from the specified node.
_traverse (line 343)

A private recursive function that performs a depth-first pre-order traversal.

  • return: array An array of all nodes in the tree visited in a pre-order manner. The keys of the array correspond to the nodes' ids. Each element of the array is another array of two elements, the first being the node itself, and the second being the depth of the node relative to the starting node. Descendants are assigned increasingly positive levels; ancestors increasingly negative levels.
  • access: private
ref _traverse (ref &$result, ref $node, boolean $down, integer $levels, integer $startingLevel, [string $initiatingNodeId = null])
  • string $initiatingNodeId: The node that initiated the traversal to this node
  • ref &$result: array The array where to store the result. Will consists of all nodes in the tree visited in a pre-order manner.
  • ref $node: object node The node to be visited.
  • boolean $down: down If
    1. true
    , this argument specifies that the traversal will go down the children; if
    1. false
    then it will go up the parents.
  • integer $levels: levels Specifies how many levels of nodes remain to be fetched. This will be recursively decremented and at 0 the recursion will stop. If this is negative then the recursion will go on until the last level is processed.
  • integer $startingLevel: startingLevels This is the original value of the levels. This is needed in order to properly calculate the relative depth of each returned node.

Inherited Methods

Inherited From TreeInterface

TreeInterface::addNode()
TreeInterface::deleteNode()
TreeInterface::getAllNodes()
TreeInterface::getAncestors()
TreeInterface::getNode()
TreeInterface::getSize()
TreeInterface::getSubtree()
TreeInterface::nodeExists()
TreeInterface::traverse()

Documentation generated on Wed, 19 Sep 2007 10:27:32 -0400 by phpDocumentor 1.3.0RC3