typescript-ds-lib
Version:
A collection of TypeScript data structure implementations
37 lines (36 loc) • 1.07 kB
TypeScript
import { Comparator } from '../types';
import { BaseCollection } from './base-collection';
export interface RedBlackTree<K, V> {
insert(key: K, value: V): void;
remove(key: K): void;
find(key: K): V | undefined;
min(): V | undefined;
max(): V | undefined;
forEach(callback: (key: K, value: V) => void): void;
}
export declare class RedBlackTree<K, V> extends BaseCollection<V> implements RedBlackTree<K, V> {
private root;
private nodeCount;
private comparator;
constructor(comparator?: Comparator<K>);
private rotateLeft;
private rotateRight;
private fixInsert;
private findNode;
private findMinNode;
private findMaxNode;
private deleteNode;
private transplant;
private fixDelete;
isEmpty(): boolean;
size(): number;
clear(): void;
private isEqual;
private inorderTraversal;
/**
* Checks if two red-black trees are equal.
* Returns false if comparing with null/undefined.
*/
equals(other: RedBlackTree<K, V>): boolean;
private areTreesEqual;
}