Click or drag to resize
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.

Inheritance Hierarchy
SystemObject
  Algs4NetTrieSTValue

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class TrieST<Value>

Type Parameters

Value

The TrieSTValue type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCount
Returns the number of key-value pairs in this symbol table.
Public propertyIsEmpty
Is this symbol table empty?
Public propertyItem
Indexer wrapping Get and Put for convenient syntax
Public propertyKeys
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).
Top
Methods
  NameDescription
Public methodContains
Does this symbol table contain the given key?
Public methodDelete
Removes the key from the set if the key is present.
Public methodGet
Returns the value associated with the given key.
Public methodKeysThatMatch
Returns all of the keys in the symbol table that match pattern, where . symbol is treated as a wildcard character.
Public methodKeysWithPrefix
Returns all of the keys in the set that start with prefix.
Public methodLongestPrefixOf
Returns the string in the symbol table that is the longest prefix of query, or null, if no such string.
Public methodStatic memberMainTest
Demo test the TrieST data type.
Public methodPut
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.
Top
Fields
  NameDescription
Public fieldStatic memberExtendedASSCII
The default alphabet for the parameterless constructor
Top
Remarks

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.

See Also