dfh.treepath
Class ParentIndex<N>

java.lang.Object
  extended by dfh.treepath.Index<N>
      extended by dfh.treepath.ParentIndex<N>
Type Parameters:
N - a type of tree node

public class ParentIndex<N>
extends Index<N>

An Index that caches the parents of nodes. This is useful for trees that don't provide backwards links from child to parent.

Author:
David F. Houghton - Apr 28, 2012

Field Summary
 
Fields inherited from class dfh.treepath.Index
f, identifiedNodes, indexed, root
 
Constructor Summary
ParentIndex(N n, Forester<N> f)
          Constructs a ParentIndex for the given tree.
 
Method Summary
protected  void index(N n, N c)
          Do relevant indexing for a parent and child pair.
 N parent(N n)
          Returns the parent of a node.
 
Methods inherited from class dfh.treepath.Index
id, index, index, indexed, isRoot, walk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParentIndex

public ParentIndex(N n,
                   Forester<N> f)
Constructs a ParentIndex for the given tree.

Parameters:
n - the root node of a tree
f - a Forester that can be used to query the nodes of the tree
Method Detail

index

protected void index(N n,
                     N c)
Description copied from class: Index
Do relevant indexing for a parent and child pair. Unless overridden this method does nothing.

Overrides:
index in class Index<N>
Parameters:
n - parent node
c - child node

parent

public N parent(N n)
Returns the parent of a node.

Parameters:
n - a node
Returns:
the parent of n