Table of Contents

Class BinaryTreeRecordStore

Namespace
BelNytheraSeiche.TrieDictionary
Assembly
BelNytheraSeiche.TrieDictionary.dll

An abstract base class for record stores that use a binary search tree to organize records.

public abstract class BinaryTreeRecordStore : BasicRecordStore
Inheritance
BinaryTreeRecordStore
Derived
Inherited Members

Remarks

This class provides the core logic for searching, enumerating, and manipulating a binary tree structure where nodes are keyed by an integer identifier. Derived classes are expected to implement the specific insertion and balancing logic (e.g., for an AVL or Red-Black tree).

Methods

Clear()

Removes all nodes from the tree, effectively clearing the store.

public override void Clear()

Contains(int)

Determines whether a record with the specified identifier exists in the store.

public override bool Contains(int identifier)

Parameters

identifier int

The identifier to locate in the tree.

Returns

bool

true if a record with the specified identifier is found; otherwise, false.

Exceptions

ArgumentOutOfRangeException

identifier is equal to MinValue, which is reserved.

Enumerate()

Returns an enumerator that iterates through all records in the store in ascending order of their identifiers.

public override IEnumerable<(int, BasicRecordStore.RecordAccess)> Enumerate()

Returns

IEnumerable<(int, BasicRecordStore.RecordAccess)>

An IEnumerable<T> of tuples, each containing the identifier and BasicRecordStore.RecordAccess for a record.

Remarks

The enumeration is performed using an in-order traversal of the binary tree.

GetRecordAccess(int, out bool)

Gets the accessor for a record with the specified identifier. If the record does not exist, it is created.

public override BasicRecordStore.RecordAccess GetRecordAccess(int identifier, out bool createNew)

Parameters

identifier int

The identifier of the record to get or create.

createNew bool

When this method returns, contains true if a new record was created; otherwise, false.

Returns

BasicRecordStore.RecordAccess

A BasicRecordStore.RecordAccess for the found or newly created record.

IsBalanced()

Checks if the binary tree is balanced.

public virtual bool IsBalanced()

Returns

bool

true if the tree is balanced; otherwise, false.

Remarks

The base implementation validates if the tree is height-balanced, meaning the height difference between the left and right subtrees of any node is no more than 1 (consistent with AVL tree properties). Derived classes that implement different balancing strategies (e.g., Red-Black Trees) should override this method to provide their own validation logic. This can be a computationally expensive operation, primarily intended for debugging and validation.

PrintTree(TextWriter)

Prints a visual representation of the tree structure to the specified TextWriter.

public void PrintTree(TextWriter textWriter)

Parameters

textWriter TextWriter

The TextWriter to output the tree structure to.

Exceptions

ArgumentNullException

textWriter is null.

TryGetRecordAccess(int, out RecordAccess?)

Tries to get the accessor for a record with the specified identifier.

public override bool TryGetRecordAccess(int identifier, out BasicRecordStore.RecordAccess? access)

Parameters

identifier int

The identifier to locate.

access BasicRecordStore.RecordAccess

When this method returns, contains the BasicRecordStore.RecordAccess object if the identifier was found; otherwise, null.

Returns

bool

true if a record with the specified identifier was found; otherwise, false.

Exceptions

ArgumentOutOfRangeException

identifier is equal to MinValue, which is reserved.