UNPKG

@linkdotnet/stringoperations

Version:

Collection of string utilities. Edit-Distances, Search and Data structures. Offers for example trie, levenshtein distance.

93 lines (92 loc) 3.83 kB
/** * Represents a rope */ export declare class Rope { private fragment; private hasToRecaluclateWeights; private left; private right; private weight; private constructor(); /** * Returns the character at the given index * @param index The zero-based index of the desired character. * @returns Returns the character at the specified index. */ charAt(index: number): string; /** * Represents the rope as a single string * @returns The whole rope as string */ toString(): string; /** * Concats a string to the rope and returns the new rope * @param other Other string which will be appended to the rope * @param recalculateWeights If set to true the weights of the new rope will be calculated immediately * @returns New rope instance with both texts * @remarks If concating a lot of strings, setting recalculateWeights to true is very expensive. * Operations which require the calculated weight will check if a recalculation is needed. * ```ts * for (let i = 0; i < 10000; i++) { * newRope = newRope.concat('test', false) * } * newRope.charAt(2) // This will automatically recalculate the weight * ``` */ concatString(other: string, recalculateWeights?: boolean): Rope; /** * Concats a rope to the current one and returns the new combined rope * @param other Other string which will be appended to the rope * @param recalculateWeights If set to true the weights of the new rope will be calculated immediately * @returns New rope instance with both texts * @remarks If concating a lot of strings, setting recalculateWeights to true is very expensive. * Operations which require the calculated weight will check if a recalculation is needed. * ```ts * for (let i = 0; i < 10000; i++) { * newRope = newRope.concat('test', false) * } * newRope.charAt(2) // This will automatically recalculate the weight * ``` */ concatRope(other: Rope | undefined, recalculateWeights?: boolean): Rope; /** * Splits the rope into two new ones at the defined index * @param index Zero based index where the rope should be split. The index is always part of the left side of the rope */ split(index: number): [Rope, Rope | undefined]; /** * Inserts another rope into the current one and returns the merger * @param rope New rope to add to the current one * @param index Zero based index where the new rope has to be inserted * @returns The merged rope */ insert(rope: Rope, index: number): Rope; /** * Inserts a string into the current rope and returns the merger * @param rope New rope to add to the current one * @param index Zero based index where the new rope has to be inserted * @returns The merged rope */ insertString(text: string, index: number): Rope; /** * Deletes a substring from the rope * @param startIndex Inclusive starting index * @param length Length to delete * @returns New rope with deleted range */ delete(startIndex: number, length: number): Rope; /** * Creates the rope with the given text * @param text The initial text to add in the rope * @param leafLength Size of a single leaf. Every leaf is a substring of the given text * @returns Instance of a rope */ static create(text: string, leafLength?: number): Rope; private static createInternal; private static getWeightInternal; private static charAtInternal; private static getStrings; private static splitRope; private calculateAndSetWeight; private checkRecalculation; }