Click or drag to resize
LinearProbingHashSTKey, Value Class

The LinearProbingHashST class represents a 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. 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 linear probing hash table. It requires that the key type overrides the Equals() and GetHashCode() methods. The expected time per Put, Contains, or Remove operation is constant, subject to the uniform hashing assumption. The Count, and IsEmpty operations take constant time. Construction takes constant time.

Inheritance Hierarchy
SystemObject
  Algs4NetLinearProbingHashSTKey, Value

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

Type Parameters

Key
Value

The LinearProbingHashSTKey, Value type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCount
Returns the number of key-value pairs in this symbol table.
Public propertyIsEmpty
Returns true if this symbol table is empty.
Public propertyItem
Indexer wrapping Get and Put for convenient syntax
Top
Methods
  NameDescription
Public methodContains
Returns true if this symbol table contains the specified key.
Public methodDelete
Removes the specified key and its associated value from this symbol table (if the key is in this symbol table).
Public methodGet
Returns the value associated with the specified key.
Public methodKeys
Returns all keys in this 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()).
Public methodStatic memberMainTest
Demo test the LinearProbingHashST data type.
Public methodPut
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.
Top
Remarks

For additional documentation, see Section 3.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

For other implementations, see SeparateChainingHashSTKey, Value. This class is a C# port from the original Java class LinearProbingHashST implementation by the respective authors.

See Also