TSTValue Class |
The TST 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 ternary search trie.
Namespace: Algs4Net
The TSTValue type exposes the following members.
Name | Description | |
---|---|---|
![]() | Count |
Returns the number of key-value pairs in this symbol table. |
![]() | 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? |
![]() | 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 TST 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. |
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 TST implementation by the respective authors.