SequentialSearchSTKey, Value Class |
The SequentialSearchST class represents an (unordered) symbol table of generic key-value pairs. It supports the usual Put, Get, Indexer, Contains, Delete, Count, and IsEmpty methods. It also provides a Keys method for iterating over all of the keys. 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. The class also 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 singly-linked list and sequential search. It relies on the Equals() method to test whether two keys are equal. It does not call either the CompareTo() or GetHashCode() method. The Put and Delete operations take linear time; the Get and Contains operations takes linear time in the worst case. The Count, and IsEmpty operations take constant time. Construction takes constant time.
Namespace: Algs4Net
The SequentialSearchSTKey, Value type exposes the following members.
Name | Description | |
---|---|---|
![]() | SequentialSearchSTKey, Value |
Initializes an empty symbol table. |
Name | Description | |
---|---|---|
![]() | Count |
Returns the number of key-value pairs in this symbol table. |
![]() | IsEmpty |
Returns true if this symbol table is empty. |
![]() | Item |
Indexer wrapping Get and Put for convenient syntax
|
Name | Description | |
---|---|---|
![]() | Contains |
Returns true if this symbol table contains the specified key. |
![]() | Delete |
Removes the specified key and its associated value from this symbol table
(if the key is in this symbol table). |
![]() | Get |
Returns the value associated with the given key in this symbol table. |
![]() | 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()). |
![]() ![]() | MainTest |
Demo test the SequentialSearchST data type. |
![]() | Put |
Inserts the specified key-value pair into the symbol table, overwriting the old
value with the new value if the symbol table already contains the specified key.
Deletes the specified key (and its associated value) from this symbol table
if the specified value is null. |
This class is a C# port from the original Java class SequentialSearchST implementation by Robert Sedgewick and Kevin Wayne.