mute-structs
Version:
NodeJS module providing an implementation of the LogootSplit CRDT algorithm
64 lines (63 loc) • 2.57 kB
TypeScript
import { Identifier } from "./identifier";
import { IdentifierInterval } from "./identifierinterval";
import { LogootSBlock } from "./logootsblock";
export declare function mkNodeAt(id: Identifier, length: number): RopesNodes;
export declare class RopesNodes {
static fromPlain(o: unknown): RopesNodes | null;
static leaf(block: LogootSBlock, offset: number, lenth: number): RopesNodes;
left: RopesNodes | null;
right: RopesNodes | null;
height: number;
block: LogootSBlock;
/**
* The current position of the beginning of the block
*
* Should always ensure that block.idInterval.begin <= actualBegin <= block.idInterval.end
*/
actualBegin: number;
/**
* The current length of the block
*
* Should always ensure that length <= to block.idInterval.end - block.idInterval.begin + 1
*/
length: number;
sizeNodeAndChildren: number;
constructor(block: LogootSBlock, actualBegin: number, length: number, left: RopesNodes | null, right: RopesNodes | null);
readonly actualEnd: number;
getIdBegin(): Identifier;
getIdEnd(): Identifier;
readonly max: Identifier;
readonly min: Identifier;
addString(length: number): void;
appendEnd(length: number): Identifier;
appendBegin(length: number): Identifier;
/**
* Delete a interval of identifiers belonging to this node
* Reduces the node"s {@link RopesNodes#length} and/or shifts its {@link RopesNodes#offset}
* May also trigger a split of the current node if the deletion cuts it in two parts
*
* @param {number} begin The start of the interval to delete
* @param {number} end The end of the interval to delete
* @returns {RopesNodes | null} The resulting block if a split occured, null otherwise
*/
deleteOffsets(begin: number, end: number): RopesNodes | null;
split(size: number, node: RopesNodes | null): RopesNodes;
leftSubtreeSize(): number;
rightSubtreeSize(): number;
sumDirectChildren(): void;
replaceChildren(node: RopesNodes, by: RopesNodes | null): void;
balanceScore(): number;
become(node: RopesNodes): void;
isAppendableAfter(replicaNumber: number, length: number): boolean;
isAppendableBefore(replicaNumber: number, length: number): boolean;
toString(): string;
/**
* @return linear representation
*/
toList(): IdentifierInterval[];
getIdentifierInterval(): IdentifierInterval;
/**
* @return list of blocks (potentially with occurrences)
*/
getBlocks(): LogootSBlock[];
}