TrieSTValue Class |
The TrieST class represents an symbol table of key-value pairs, with string keys and generic values. It supports the usual Put, Get, Indexer, Contains, Delete, Count, and IsEmpty methods. It also provides character-based methods for finding the string in the symbol table that is the Longest prefix of a given prefix, finding all strings in the symbol table that Start with a given prefix, and finding all strings in the symbol table that Match a given pattern. A symbol table implements the Associative array abstraction: when associating a value with a key that is already in the symbol table, the convention is to replace the old value with the new value. Unlike DictionaryTKey, TValue, this class uses the convention that values cannot be null. Setting the value associated with a key to null is equivalent to deleting the key from the symbol table.
This implementation uses a 256-way trie. The Put, Contains, Delete, and Longest prefix operations take time proportional to the length of the key (in the worst case). Construction takes constant time. The Count, and IsEmpty operations take constant time. Construction takes constant time.
Namespace: Algs4Net
The TrieSTValue type exposes the following members.
Name | Description | |
---|---|---|
![]() | TrieSTValue |
Initializes an empty string symbol table using the default alphabet. |
![]() | TrieSTValue(Alphabet) |
Initializes an empty string symbol table. |
Name | Description | |
---|---|---|
![]() | Count |
Returns the number of key-value pairs in this symbol table. |
![]() | IsEmpty |
Is this symbol table empty? |
![]() | Item |
Indexer wrapping Get and Put for convenient syntax
|
![]() | Keys |
Returns all keys in the symbol table as an Iterable.
To iterate over all of the keys in the symbol table named st,
use the foreach notation: foreach (Key key in st.Keys). |
Name | Description | |
---|---|---|
![]() | Contains |
Does this symbol table contain the given key? |
![]() | Delete |
Removes the key from the set if the key is present. |
![]() | Get |
Returns the value associated with the given key. |
![]() | KeysThatMatch |
Returns all of the keys in the symbol table that match pattern,
where . symbol is treated as a wildcard character. |
![]() | KeysWithPrefix |
Returns all of the keys in the set that start with prefix. |
![]() | LongestPrefixOf |
Returns the string in the symbol table that is the longest prefix of query,
or null, if no such string. |
![]() ![]() | MainTest |
Demo test the TrieST data type. |
![]() | Put |
Inserts the key-value pair into the symbol table, overwriting the old value
with the new value if the key is already in the symbol table.
If the value is null, this effectively deletes the key from the symbol table. |
Name | Description | |
---|---|---|
![]() ![]() | ExtendedASSCII |
The default alphabet for the parameterless constructor
|
For additional documentation, see Section 5.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
This class is a C# port from the original Java class TrieST implementation by the respective authors.