Class VersionVector

VersionVector is a map from [PeerID] to [Counter]. Its a right-open interval.

i.e. a [VersionVector] of {A: 1, B: 2} means that A has 1 atomic op and B has 2 atomic ops, thus ID of {client: A, counter: 1} is out of the range.

Constructors

  • Create a new version vector.

    Parameters

    • value: Uint8Array<ArrayBufferLike> | VersionVector | Map<`${number}`, number>

    Returns VersionVector

Methods

  • Compare the version vector with another version vector.

    If they are concurrent, return undefined.

    Parameters

    Returns number

  • Encode the version vector into a Uint8Array.

    Returns Uint8Array

  • Returns void

  • Get the counter of a peer.

    Parameters

    • peer_id: number | bigint | `${number}`

    Returns number

  • Returns number

  • Parameters

    • peer: `${number}`

    Returns void

  • set the exclusive ending point. target id will NOT be included by self

    Parameters

    • id: { counter: number; peer: `${number}` }

    Returns void

  • set the inclusive ending point. target id will be included

    Parameters

    • id: { counter: number; peer: `${number}` }

    Returns void

  • Convert the version vector to a Map

    Returns Map<`${number}`, number>

  • Decode the version vector from a Uint8Array.

    Parameters

    • bytes: Uint8Array

    Returns VersionVector

  • Create a new version vector from a Map.

    Parameters

    • version: Map<`${number}`, number>

    Returns VersionVector