Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LocalList<T>

A local (non-collaborative) data structure mapping Positions to values, in list order.

You can use a LocalList to maintain a sorted, indexable view of a CValueList, CList, or CText's values. For example, when using a CList, you could store its archived values in a LocalList. That would let you iterate over the archived values in list order.

To construct a LocalList that uses an existing list's positions, pass that list's totalOrder to our constructor.

It is not safe to modify a LocalList while iterating over it. The iterator will attempt to throw an exception if it detects such modification, but this is not guaranteed.

Type Parameters

  • T

    The value type.

Hierarchy

  • LocalList

Implements

Index

Constructors

  • Constructs a LocalList whose allowed Positions are given by source.

    Using positions that were not generated by source (or a replica of source) will cause undefined behavior.

    Type Parameters

    • T

    Parameters

    • source: CTotalOrder

      The source for positions that may be used with this LocalList.

    Returns LocalList<T>

Properties

source: CTotalOrder

Accessors

  • get inInitialState(): boolean
  • Whether this list is in its initial state, i.e., it has never been mutated.

    Returns boolean

  • get length(): number
  • The length of the list.

    Returns number

Methods

  • [iterator](): IterableIterator<T>
  • Returns an iterator for values in the list, in list order.

    Returns IterableIterator<T>

  • delete(position: string): boolean
  • Deletes the given position, making it no longer present in this list.

    Parameters

    • position: string

    Returns boolean

    Whether the position was actually deleted, i.e., it was initially present.

  • entries(): IterableIterator<[index: number, value: T, position: string]>
  • Returns an iterator of [index, value, position] tuples for every value in the list, in list order.

    Returns IterableIterator<[index: number, value: T, position: string]>

  • get(index: number): T
  • Returns the value currently at index.

    throws

    If index is not in [0, this.length). Note that this differs from an ordinary Array, which would instead return undefined.

    Parameters

    • index: number

    Returns T

  • getByPosition(position: string): undefined | T
  • Returns the value at position, or undefined if it is not currently present (hasPosition returns false).

    Parameters

    • position: string

    Returns undefined | T

  • getPosition(index: number): string
  • Returns the position currently at index.

    Parameters

    • index: number

    Returns string

  • Returns the number of "seen" positions for waypoint.

    This is useful in some optimized list CRDTs.

    Specifically, the return value is 1 + the max valueIndex across all positions of the form [waypoint, valueIndex] that have been passed to set or setCreated.

    Parameters

    Returns number

  • hasPosition(position: string): boolean
  • Returns whether position is currently present in the list, i.e., its value is present.

    Parameters

    • position: string

    Returns boolean

  • indexOfPosition(position: string, searchDir?: "none" | "left" | "right"): number
  • Returns the current index of position.

    If position is not currently present in the list (hasPosition returns false), then the result depends on searchDir:

    • "none" (default): Returns -1.
    • "left": Returns the next index to the left of position. If there are no values to the left of position, returns -1.
    • "right": Returns the next index to the right of position. If there are no values to the right of position, returns length.

    To find the index where a position would be if present, use searchDir = "right".

    Parameters

    • position: string
    • Optional searchDir: "none" | "left" | "right"

    Returns number

  • load(savedState: Uint8Array, valueArraySerializer: Serializer<T[]>): void
  • Loads saved state. The saved state must be from a call to save on a LocalList whose source constructor argument was a replica of this's source, so that we can understand the saved state's Positions.

    This method may only be called on a LocalList in its initial state (see inInitialState); it does not support "merging" in the sense of CRuntime.load.

    Parameters

    • savedState: Uint8Array

      Saved state from another LocalList's save call.

    • valueArraySerializer: Serializer<T[]>

      Used to deserialize values. Must be equivalent to save's valueArraySerializer.

    Returns void

  • positions(): IterableIterator<string>
  • Returns an iterator for present positions, in list order.

    Returns IterableIterator<string>

  • save(valueArraySerializer: Serializer<T[]>): Uint8Array
  • Returns saved state describing the current state of this LocalList, including its values.

    The saved state may later be passed to load on a new instance of LocalList, to reconstruct the same list state.

    Parameters

    • valueArraySerializer: Serializer<T[]>

      Used to serialize values. Note that this may be called multiple times on distinct value arrays, and value arrays may contain non-contiguous values.

    Returns Uint8Array

  • set(position: string, value: T): void
  • Sets the value at position.

    Parameters

    • position: string
    • value: T

    Returns void

  • setCreated(firstPos: string, values: T[]): void
  • Optimized variant of set for newly-created positions.

    If you (or a remote replica) just created values.count positions using [[CTotalOrder.createPosition]], you may call this method with the first created position and the values to set at the created positions. This may be faster than calling set on each (position, value) individually.

    throws

    If firstPos has been seen before, i.e., it or a later position has been set.

    Parameters

    • firstPos: string

      The position for values[0].

    • values: T[]

      The values to set.

    Returns void

  • slice(start?: number, end?: number): T[]
  • Returns a copy of a section of this list, as an array. For both start and end, a negative index can be used to indicate an offset from the end of the list. For example, -2 refers to the second to last element of the list.

    Parameters

    • Optional start: number

      The beginning index of the specified portion of the list. If start is undefined, then the slice begins at index 0.

    • Optional end: number

      The end index of the specified portion of the list. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the list.

    Returns T[]

  • values(): IterableIterator<T>
  • Returns an iterator for values in the list, in list order.

    Returns IterableIterator<T>

Generated using TypeDoc