Package edu.ksu.cis.viewer
Class PatriciaTrie
java.lang.Object
edu.ksu.cis.viewer.PatriciaTrie
- All Implemented Interfaces:
BSTInterface
,TreeInterface
,Serializable
An immutable Patricia trie that can draw itself. The trie is immutable in
the sense that any PatriciaTrie returned by a public constructor or method
cannot subsequently be changed. A Patricia trie contains a set of strings.
Each subtree stores in its root the longest common prefix of all strings
contained within that subtree. For each string stored in the subtree, a
suffix is computed by removing the prefix stored in the root. If there is
more than one such suffix, each of the suffixes is stored in one of the
children, a different child for each distinct character beginning a suffix,
plus a child for the empty suffix if it is present. Note that according
to these rules, no node other than the root or a leaf will store an empty
string.
- Author:
- Rod Howell (rhowell@ksu.edu)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
Because this structure is immutable, this method simply returns thisPatriciaTrie
.Returns the children of thisPatriciaTrie
.Returns a drawing of thisPatriciaTrie
.getDrawing
(Font fnt) Returns a drawing of this tree using the given Font.getRoot()
Returns the root of thisPatriciaTrie
.boolean
isEmpty()
Returnstrue
if thisPatriciaTrie
is empty.Returns thePatriciaTrie
resulting from the insertion ofkey
into thisPatriciaTrie
.Returns thePatriciaTrie
resulting from the removal ofkey
from thisPatriciaTrie
.
-
Constructor Details
-
PatriciaTrie
public PatriciaTrie()Constructs an empty PatriciaTrie.
-
-
Method Details
-
put
Returns thePatriciaTrie
resulting from the insertion ofkey
into thisPatriciaTrie
. Ifkey
is already in thisPatriciaTrie
, an identicalTrie
will be returned.- Specified by:
put
in interfaceBSTInterface
- Parameters:
key
- the key to insert- Returns:
- the resutling tree
- Throws:
NullPointerException
- Ifkey
isnull
-
remove
Returns thePatriciaTrie
resulting from the removal ofkey
from thisPatriciaTrie
. Ifkey
is not in thisPatriciaTrie
, an identicalPatriciaTrie
is returned.- Specified by:
remove
in interfaceBSTInterface
- Parameters:
key
- the key to remove- Returns:
- the resulting tree
- Throws:
NullPointerException
- If key isnull
-
getDrawing
Returns a drawing of thisPatriciaTrie
.- Specified by:
getDrawing
in interfaceBSTInterface
- Returns:
- a drawing of the tree
-
getDrawing
Returns a drawing of this tree using the given Font.- Specified by:
getDrawing
in interfaceBSTInterface
- Parameters:
fnt
- the font to use- Returns:
- a drawing of the tree
- Throws:
NullPointerException
- iffnt
isnull
.
-
clone
Because this structure is immutable, this method simply returns thisPatriciaTrie
.- Specified by:
clone
in interfaceBSTInterface
- Overrides:
clone
in classObject
- Returns:
- a clone of the this tree
-
getRoot
Returns the root of thisPatriciaTrie
. This method is intended for use by theTreeDrawing
class.- Specified by:
getRoot
in interfaceTreeInterface
- Returns:
- the root of this tree
- See Also:
-
getChildren
Returns the children of thisPatriciaTrie
. This method is intended for use by theTreeDrawing
class.- Specified by:
getChildren
in interfaceTreeInterface
- Returns:
- an array containing the children of this tree
-
isEmpty
public boolean isEmpty()Returnstrue
if thisPatriciaTrie
is empty. This method is intended for use by theTreeDrawing
class.- Specified by:
isEmpty
in interfaceTreeInterface
- Returns:
- whether this tree is empty
-