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.
Namespace: Algs4Net
The BTreeKey, Value type exposes the following members.
Name | Description | |
---|---|---|
![]() | BTreeKey, Value |
Initializes an empty B-tree. |
Name | Description | |
---|---|---|
![]() | Count |
Returns the number of key-value pairs in this symbol table. |
![]() | Height |
Returns the height of this B-tree (for debugging). |
![]() | IsEmpty |
Returns true if this symbol table is empty. |
![]() | Item |
Indexer wrapping Get and Put for convenient syntax
|
Name | Description | |
---|---|---|
![]() | Get |
Returns the value associated with the given key. |
![]() ![]() | MainTest |
Demo test the BTree 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. |
![]() | ToString |
Returns a string representation of this B-tree (for debugging). (Overrides ObjectToString.) |
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.