@sovereignbase/hybrid-logical-clock
    Preparing search index...

    Class HLC

    Represents a hybrid logical clock backed by a UUIDv7 timestamp encoded as four unsigned 32-bit integer lanes.

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Creates a new hybrid logical clock seeded with a UUIDv7 timestamp.

      Returns HLC

    Properties

    The current UUIDv7 timestamp.

    The timestamp is stored as four unsigned 32-bit lanes ordered from highest significance to lowest significance:

    [first32bits, second32bits, third32bits, fourth32bits]

    Methods

    • Compares two hybrid logical clock timestamps by their UUIDv7 timestamp.

      Use this only when both timestamps have the same previous timestamp.

      Parameters

      Returns number

      -1 if left is before right in logical time, 1 if left is after right in logical time, and 0 if both timestamps are equal.

    • Advances the current timestamp by the given clock advancement.

      The advancement is added to the fourth 32-bit lane. Overflow is carried into the third, second, and first 32-bit lanes in that order.

      This method mutates HLC.time in place and returns an HLC timestamp linking the previous timestamp to a stable copy of this timestamp.

      Parameters

      • advancement: number = 1

        The clock advancement to add to the timestamp.

      • previousTimestamp: PreviousTimestamp = CLOCK_START

        The previous timestamp, or CLOCK_START when this is the first timestamp.

      Returns HLCTimestamp

      The linked hybrid logical clock timestamp.

    • Determines whether the given value is a valid hybrid logical clock timestamp.

      Parameters

      • timestamp: unknown

        The value to validate.

      Returns timestamp is HLCTimestamp

      true if timestamp is a valid HLCTimestamp; otherwise false.