Home Reference Source Repository
import LSeqTree from 'lseqtree'
public class | source

LSeqTree

Distributed array using LSeq allocation strategy with an underlying exponential tree.

Constructor Summary

Public Constructor
public

constructor(source: Object, options: Object)

Member Summary

Public Members
public get

length: *

public

options: *

public

root: *

Private Members
private

_base: *

private
private
private

_hash: *

private

_s: *

private

Method Summary

Public Methods
public

Generate the digit part of the identifiers between p and q.

public

applyInsert(pair: Object, noIndex: boolean): Number | Boolean

Insert an element created from a remote site into the array.

public

Delete the element with the targeted identifier.

public

Cast the JSON object into a proper LSeqTree.

public

get(index: Number): Object

Get the element at targeted index in the linearized sequence.

public

insert(element: Object, index: Number): Object

Insert a value at the targeted index.

public

Delete the element at the index.

Private Methods
private

_get(index: Number): LSeqNode

Public Constructors

public constructor(source: Object, options: Object) source

Params:

NameTypeAttributeDescription
source Object

The globally unique site identifier.

options Object
  • optional

The options of the LSeqTree.

options.boundary Number
  • optional
  • default: 10

The maximal interval between two generated nodes.

options.base Number
  • optional
  • default: 15

The base, i.e., the maximal arity of the root node. Default is 2**15.

Public Members

public get length: * source

public options: * source

public root: * source

Private Members

private _base: * source

private _boundary: * source

private _c: number source

private _hash: * source

private _s: * source

private _strategy: * source

Public Methods

public alloc(p: LSeqNode, q: LSeqNode): Identifier source

Generate the digit part of the identifiers between p and q.

Params:

NameTypeAttributeDescription
p LSeqNode

The digit part of the previous identifier.

q LSeqNode

The digit part of the next identifier.

Return:

Identifier

The new identifier located between p and q.

public applyInsert(pair: Object, noIndex: boolean): Number | Boolean source

Insert an element created from a remote site into the array.

Params:

NameTypeAttributeDescription
pair Object

Pair containing the identifier and the element to insert in the data structure.

pair.id Identifier | LSeqNode

The identifier of the element.

pair.elem Object

The element to insert.

noIndex boolean
  • optional
  • default: true

Whether or not it should return the index of the insert.

Return:

Number | Boolean

The index of the newly inserted element in the array, if asked. -1 if the element already exists and has not been added. If noIndex, returns true if the element has been added, false otherwise.

public applyRemove(i: Identifier | LSeqNode): Number source

Delete the element with the targeted identifier.

Params:

NameTypeAttributeDescription
i Identifier | LSeqNode

The identifier of the element.

Return:

Number

The index of the element freshly deleted, -1 if no removal.

public fromJSON(object: Object): LSeqTree source

Cast the JSON object into a proper LSeqTree.

Params:

NameTypeAttributeDescription
object Object

the JSON object to cast.

Return:

LSeqTree

A self reference.

public get(index: Number): Object source

Get the element at targeted index in the linearized sequence. It does not take into account the hidden boundaries of the sequence [MIN, e_1, e_2, ... e_length, MAX], hence index of e_1 is 0.

Params:

NameTypeAttributeDescription
index Number

The index of the element in the flattened array.

Return:

Object

The element located at the index in argument.

public insert(element: Object, index: Number): Object source

Insert a value at the targeted index.

Params:

NameTypeAttributeDescription
element Object

The element to insert, e.g. a character if the sequence is a string.

index Number

The position in the array.

Return:

Object

{_e: element of Object type, _i: Identifier}

public remove(index: Number): Identifier source

Delete the element at the index.

Params:

NameTypeAttributeDescription
index Number

The index of the element to delete in the array.

Return:

Identifier

The identifier of the element at the index.

Private Methods

private _get(index: Number): LSeqNode source

Params:

NameTypeAttributeDescription
index Number

The index of the element in the flattened array.

Return:

LSeqNode

The LSeqNode targeting the element at index.