Click or drag to resize
BTreeKey, Value Class

The BTree class represents an ordered symbol table of generic key-value pairs. It supports the Put, Get, IndexerContains, Count, and IsEmpty methods.

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 B-tree. It requires that the key type implements the IComparable interface and calls the CompareTo() and method to compare two keys. It does not call either Equals() or GetHashCode(). The Get, Put, and Contains operations each make logM(N) probes in the worst case, where N is the number of key-value pairs and M is the branching factor. The Count, and IsEmpty operations take constant time. Construction takes constant time.

Inheritance Hierarchy
SystemObject
  Algs4NetBTreeKey, Value

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

Type Parameters

Key
Value

The BTreeKey, Value type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCount
Returns the number of key-value pairs in this symbol table.
Public propertyHeight
Returns the height of this B-tree (for debugging).
Public propertyIsEmpty
Returns true if this symbol table is empty.
Public propertyItem
Indexer wrapping Get and Put for convenient syntax
Top
Methods
  NameDescription
Public methodGet
Returns the value associated with the given key.
Public methodStatic memberMainTest
Demo test the BTree 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.
Public methodToString
Returns a string representation of this B-tree (for debugging).
(Overrides ObjectToString.)
Top
Remarks

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

This class is a C# port from the original Java class BTree implementation by the respective authors.

See Also