Package com.globalmentor.collections
Class SuffixTrees
- java.lang.Object
-
- com.globalmentor.collections.SuffixTrees
-
public class SuffixTrees extends java.lang.Object
Utilities for working with suffix trees.- Author:
- Garret Wilson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SuffixTrees.Visitor<N extends SuffixTree.Node,E extends SuffixTree.Edge>
A general visitor strategy for visiting nodes.
-
Constructor Summary
Constructors Constructor Description SuffixTrees()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
print(SuffixTree suffixTree, java.io.PrintStream printStream)
Prints a character representation of the tree and its branches, starting from the root node.protected static void
print(SuffixTree suffixTree, java.io.PrintStream printStream, SuffixTree.Edge edge, int level)
Prints a character representation of the child edges of the given edge.protected static void
print(SuffixTree suffixTree, java.io.PrintStream printStream, SuffixTree.Node node, int level)
Prints a character representation of the given node.static <N extends SuffixTree.Node,E extends SuffixTree.Edge>
booleanvisit(SuffixTree suffixTree, SuffixTrees.Visitor<N,E> visitor)
Recursively visits all the nodes in a given suffix tree.static <N extends SuffixTree.Node,E extends SuffixTree.Edge>
booleanvisit(SuffixTree suffixTree, N node, E parentEdge, int length, SuffixTrees.Visitor<N,E> visitor)
Recursively visits a given node and all descendant nodes in a subtree of a suffix tree.static <N extends SuffixTree.Node,E extends SuffixTree.Edge>
booleanvisitChildren(SuffixTree suffixTree, N node, int length, SuffixTrees.Visitor<N,E> visitor)
Recursively visits all descendant nodes in a subtree of a suffix tree.
-
-
-
Method Detail
-
print
public static void print(SuffixTree suffixTree, java.io.PrintStream printStream)
Prints a character representation of the tree and its branches, starting from the root node.- Parameters:
suffixTree
- The suffix tree to print.printStream
- The destination to which the tree should be printed.- Throws:
java.lang.NullPointerException
- if the given suffix tree and/or print stream isnull
.
-
print
protected static void print(SuffixTree suffixTree, java.io.PrintStream printStream, SuffixTree.Node node, int level)
Prints a character representation of the given node.- Parameters:
suffixTree
- The suffix tree to print.printStream
- The destination to which the tree should be printed.node
- The node the child edges to print.level
- The zero-based level of the tree from the root.- Throws:
java.lang.NullPointerException
- if the given suffix tree, print stream, and/or node isnull
.
-
print
protected static void print(SuffixTree suffixTree, java.io.PrintStream printStream, SuffixTree.Edge edge, int level)
Prints a character representation of the child edges of the given edge.- Parameters:
suffixTree
- The suffix tree to print.printStream
- The destination to which the tree should be printed.edge
- The edge the child edges of which to print.level
- The zero-based level of the tree from the root.- Throws:
java.lang.NullPointerException
- if the given suffix tree and/or print stream and/or edge isnull
.
-
visit
public static <N extends SuffixTree.Node,E extends SuffixTree.Edge> boolean visit(SuffixTree suffixTree, SuffixTrees.Visitor<N,E> visitor)
Recursively visits all the nodes in a given suffix tree.- Type Parameters:
N
- The type of node.E
- The type of edge.- Parameters:
suffixTree
- The suffix tree to visit.visitor
- The visitor to visit the nodes of the suffix tree.- Returns:
true
if visiting completed all the nodes.- Throws:
java.lang.NullPointerException
- if the given suffix tree and/or visitor isnull
.
-
visit
public static <N extends SuffixTree.Node,E extends SuffixTree.Edge> boolean visit(SuffixTree suffixTree, N node, E parentEdge, int length, SuffixTrees.Visitor<N,E> visitor)
Recursively visits a given node and all descendant nodes in a subtree of a suffix tree.- Type Parameters:
N
- The type of node.E
- The type of edge.- Parameters:
suffixTree
- The suffix tree to visit.node
- The node being visited.parentEdge
- The parent edge of the node being visited, ornull
if the node has no parent.length
- The length of elements up to the visited node, including the length of the parent edge.visitor
- The visitor to visit the nodes of the suffix tree.- Returns:
true
if visiting completed all the nodes.
-
visitChildren
public static <N extends SuffixTree.Node,E extends SuffixTree.Edge> boolean visitChildren(SuffixTree suffixTree, N node, int length, SuffixTrees.Visitor<N,E> visitor)
Recursively visits all descendant nodes in a subtree of a suffix tree.- Type Parameters:
N
- The type of node.E
- The type of edge.- Parameters:
suffixTree
- The suffix tree to visit.node
- The node being visited.length
- The length of elements up to the visited node, including the length of the parent edge.visitor
- The visitor to visit the nodes of the suffix tree.- Returns:
true
if visiting completed all the nodes.
-
-