Package dsa
Class TrieST<V>
java.lang.Object
dsa.TrieST<V>
- Type Parameters:
V
- the type of values in the trie.
A data type to represent the trie data structure, which is a symbol table with string keys.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if this symbol table containskey
, andfalse
otherwise.void
Deleteskey
and the associated value from this symbol table.Returns the value associated withkey
in this symbol table, ornull
.boolean
isEmpty()
Returnstrue
if this symbol table is empty, andfalse
otherwise.keys()
Returns all the keys in this symbol table.keysThatMatch
(String pattern) Returns all the keys in this symbol table that matchpattern
, where the.
symbol is treated as a wildcard character.keysWithPrefix
(String prefix) Returns all the keys in this symbol table that start withprefix
.longestPrefixOf
(String query) Returns the string in this symbol table that is the longest prefix ofquery
, ornull
.static void
Unit tests the data type.void
Inserts thekey
andvalue
pair into this symbol table.int
size()
Returns the number of key-value pairs in this symbol table.toString()
Returns a string representation of this symbol table.
-
Constructor Details
-
TrieST
public TrieST()Constructs an empty symbol table.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returnstrue
if this symbol table is empty, andfalse
otherwise.- Returns:
true
if this symbol table is empty, andfalse
otherwise.
-
size
public int size()Returns the number of key-value pairs in this symbol table.- Returns:
- the number of key-value pairs in this symbol table.
-
put
Inserts thekey
andvalue
pair into this symbol table.- Parameters:
key
- the key.value
- the value.
-
get
Returns the value associated withkey
in this symbol table, ornull
.- Parameters:
key
- the key.- Returns:
- the value associated with
key
in this symbol table, ornull
.
-
contains
Returnstrue
if this symbol table containskey
, andfalse
otherwise.- Parameters:
key
- the key.- Returns:
true
if this symbol table contains key, andfalse
otherwise.
-
delete
Deleteskey
and the associated value from this symbol table.- Parameters:
key
- the key.
-
keys
Returns all the keys in this symbol table.- Returns:
- all the keys in this symbol table.
-
keysWithPrefix
Returns all the keys in this symbol table that start withprefix
.- Parameters:
prefix
- the prefix.- Returns:
- all the keys in this symbol table that start with
prefix
.
-
keysThatMatch
Returns all the keys in this symbol table that matchpattern
, where the.
symbol is treated as a wildcard character.- Parameters:
pattern
- the pattern.- Returns:
- all the keys in this symbol table that match
pattern
, where the.
symbol is treated as a wildcard character.
-
longestPrefixOf
Returns the string in this symbol table that is the longest prefix ofquery
, ornull
.- Parameters:
query
- the string.- Returns:
- the string in this symbol table that is the longest prefix of
query
, ornull
.
-
toString
Returns a string representation of this symbol table. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-