Collection Kit

Rope

String

A Rope is a binary tree used to store and manipulate long strings efficiently. It allows for fast concatenation and substring operations.

Import Statement
import { Rope } from "collection-kit";

Key Features

  • Efficient String Manipulation: Supports fast operations on long strings.
  • Dynamic Structure: Can grow and shrink as strings are modified.

Common Operations

Insert
Add a substring to the rope.
Delete
Remove a substring from the rope.
Substring
Retrieve a substring from the rope.

Example Code

import { Rope } from "collection-kit";

const rope = new Rope("Hello");
rope.insert(5, " World");

console.log("String:", rope.toString());      // "Hello World"
console.log("Substring:", rope.substring(0, 5)); // "Hello"