Skip to content

Latest commit

History

History
47 lines (27 loc) 路 1.23 KB

README.org

File metadata and controls

47 lines (27 loc) 路 1.23 KB

Data.Rope

A rope is a tree-like data structure that provides a more efficient way of concatenating strings. A valid rope must be either a node or a leaf. More specifically:

  • A rope leaf always contains some string (whether it be empty or not).
  • A rope node contains no string, but references to it鈥檚 left and right child nodes. The total length of all it鈥檚 children鈥檚 is a rope node鈥檚 value.

Module Exports

data Rope = Leaf String | Node Int Rope Rope

concat' :: Rope -> Rope -> Rope

Concatenates two Ropes. Time complexity: O(1).

delete :: Rope -> Int -> Int -> Rope

Deletes substring in Rope for given range. Time complexity: O(log N).

index :: Rope -> Int -> Char

Get Char from Rope at index. Time complexity: O(log N).

insert :: Rope -> Int -> String -> Rope

Inserts String into Rope at index. Time complexity: O(log N).

length' :: Rope -> Int

Gets length of Rope. Time complexity: O(1).

split :: Rope -> Int -> (Rope, Rope)

Splits Rope at index into a Rope tuple. Time complexity: O(log N).

substring :: Rope -> Int -> Int -> String

Gets substring for range in Rope. Time complexity: O(log N).

toString :: Rope -> String

Casts Rope into String. Time complexity: O(N).