import { BinaryTreeNode } from '../data-structures'; import type { BinaryTreeDeleteResult, BinaryTreeOptions, BTNRep, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNodeOrNull, ReduceEntryCallback, ToEntryFn } from '../types'; /** * Public, implementation-agnostic binary tree API. * K = key, V = value, R = raw/record used with toEntryFn (optional). * Transforming methods like `map` use method-level generics MK/MV/MR. */ export interface IBinaryTree { // ---- state ---- readonly size: number; readonly root: BinaryTreeNode | null | undefined; readonly isMapMode: boolean; // NOTE: iterationType is mutable on the class; remove readonly here to match iterationType: IterationType; // Extra public state/getters implemented by BinaryTree (useful to callers) readonly NIL: BinaryTreeNode; readonly store: Map>; readonly toEntryFn?: ToEntryFn; readonly isDuplicate: boolean; // ---- construction / mutation ---- createNode(key: K, value?: BinaryTreeNode['value']): BinaryTreeNode; createTree(options?: Partial>): IBinaryTree; add(keyOrNodeOrEntryOrRawElement: BTNRep>, value?: V, count?: number): boolean; set(keyOrNodeOrEntryOrRawElement: BTNRep>, value?: V, count?: number): boolean; // Accept raw R as well (when toEntryFn is configured) addMany( keysNodesEntriesOrRaws: Iterable< K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined | R >, values?: Iterable ): boolean[]; // Accept BTNRep, predicate, or raw R for deletion delete( keyNodeEntryRawOrPredicate: BTNRep> | NodePredicate | null> ): BinaryTreeDeleteResult>[]; clear(): void; isEmpty(): boolean; // ---- query / read ---- // Widen `get` to support entry and optional traversal context (matches impl) get( keyNodeEntryOrPredicate: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): V | undefined; // `has` also supports node/entry/predicate and optional traversal context has( keyNodeEntryOrPredicate?: | K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined | NodePredicate | null>, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): boolean; hasValue(value: V): boolean; find(predicate: EntryCallback, thisArg?: unknown): [K, V | undefined] | undefined; // ---- iteration ---- [Symbol.iterator](): IterableIterator<[K, V | undefined]>; entries(): IterableIterator<[K, V | undefined]>; keys(): IterableIterator; values(): IterableIterator; forEach(callbackfn: EntryCallback, thisArg?: unknown): void; every(callbackfn: EntryCallback, thisArg?: unknown): boolean; some(callbackfn: EntryCallback, thisArg?: unknown): boolean; reduce(reducer: ReduceEntryCallback, initialValue: U): U; // ---- node access / extremes ---- getNode( keyNodeEntryOrPredicate: | K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined | NodePredicate | null>, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): OptNodeOrNull>; getLeftMost>>>( callback?: C, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): ReturnType; getRightMost | undefined>>( callback?: C, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): ReturnType; // ---- traversal ---- dfs>>( callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): ReturnType[]; dfs | null>>( callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: boolean ): ReturnType[]; bfs>>( callback?: C, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false ): ReturnType[]; bfs | null>>( callback?: C, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true ): ReturnType[]; morris | null>>( callback?: C, pattern?: DFSOrderPattern, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined ): ReturnType[]; leaves | null>>( callback?: C, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): ReturnType[]; listLevels>>( callback?: C, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false ): ReturnType[][]; listLevels | null>>( callback?: C, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true ): ReturnType[][]; getPathToRoot>>>( beginNode: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, callback?: C, isReverse?: boolean ): ReturnType[]; // ---- metrics & validation ---- getDepth( dist: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined ): number; getHeight( startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): number; getMinHeight( startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): number; isPerfectlyBalanced( startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined ): boolean; isBST( startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): boolean; // ---- search helpers ---- search | null>>( keyNodeEntryOrPredicate: | K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined | NodePredicate | null>, onlyOne?: boolean, callback?: C, startNode?: K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType ): ReturnType[]; // ---- immutable transforms ---- clone(): this; filter(predicate: EntryCallback, thisArg?: unknown): this; map( callback: EntryCallback, options?: Partial>, thisArg?: unknown ): IBinaryTree; // ---- bulk / interop ---- merge(anotherTree: IBinaryTree): void; refill( keysNodesEntriesOrRaws: Iterable< K | BinaryTreeNode | [K | null | undefined, V | undefined] | null | undefined | R >, values?: Iterable ): void; }