UNPKG

rope-structure

Version:

A Rope Data Structure implementation which is used for efficient text editing and used widely in text editors.

37 lines (35 loc) 998 B
type RopeNodeType = "LEAF" | "INTERNAL"; declare class RopeNode { left: RopeNode | null; right: RopeNode | null; parent: RopeNode | null; weight: number; value: string; type: RopeNodeType; height: number; constructor(value?: string); } declare class Rope { private root; private readonly LEAF_LENGTH_THRESHOLD; private readonly REBALANCE_RATIO; constructor(initialString?: string); private createOptimalTree; private updateNodeMetadata; private getNodeWeight; private getBalanceFactor; private rotateRight; private rotateLeft; private balance; insert(index: number, text: string): void; delete(start: number, end: number): void; charAt(index: number): string; substring(start: number, end?: number): string; private concat; private split; length(): number; toString(node?: RopeNode | null): string; isBalanced(): boolean; rebalance(): void; } export { RopeNode, Rope as default };