4bitlabs Low-Level Bit/Byte Utilities
    Preparing search index...

    Class BigVector<T>

    The BigVector is a resizable data-structure for storing int64 and uint64 entries.

    const signedVector = new BigVector(BigInt64Array);
    const unsignedVector = new BigVector(BigUint64Array);

    Then, you can push() and pop() entries from the BigVector.

    signedVector.push(1n);
    signedVector.push(-1n);
    unsignedVector.push(1n);
    unsignedVector.push(0xFFFF_FFFF_FFFF_FFFFn);

    Type Parameters

    Index
    • get capacity(): number

      Current the current length of the backing BigTypedArray. This is the maximum number of elements this BigVector can hold before it will be resized.

      Returns number

    • get length(): number

      Get the current length of the BigVector, will always been less-than-or-equal to BigVector.capacity.

      Returns number

    • Set the value at the given index.

      Parameters

      • index: number

        The index of the element to set.

      • value: bigint

        The value of the element.

      Returns void

      Error if the index is out of range.

    • Retrieves the element at the given index.

      Parameters

      • index: number

        The index of the element to get.

      Returns bigint

      Error if the index is out of range.

    • Set multiple values starting at begin.

      Parameters

      • begin: number

        The index to start at.

      • values: ArrayLike<bigint>

        The values to set.

      Returns void

    • Push elements onto the end of the BigVector, resizing if needed.

      Parameters

      • ...args: bigint[]

        The values to push to the end of the vector.

      Returns number

      The new length of the vector.

    • Push multiple elements onto the end of the BigVector, resizing multiple-times if needed.

      Parameters

      • values: ArrayLike<bigint>

      Returns number

    • Remove and return a single element from the end of the BigVector.

      Returns bigint | undefined

      The removed value, unless the BigVector is empty, then undefined.

    • Remove and return a multiple elements from the end of the BigVector.

      Parameters

      • count: number

      Returns T

      A BigTypedArray of the removed values.

      const vec = BigVector.from([1, 2, 3, 4, 5], Uint8Array);
      const three = vec.popN(3);
    • Remove and return a multiple elements from the end of the BigVector.

      Parameters

      • count: number
      • dest: T

      Returns T

      A BigTypedArray of the removed values.

      const vec = BigVector.from([1, 2, 3, 4, 5], Uint8Array);
      const three = vec.popN(3);
    • Manually trigger the BigVector to grow in size, using the growth behavior.

      Returns this

    • Reallocate the underlying BigTypedArray.

      If the capacity is less-than the current length, then the extra values are discarded.

      Parameters

      • capacity: number = ...

        The desired capacity of the BigVector. Defaults to the current length of the BigVector.

      Returns this

    • Clear all entries from the BigVector

      Returns this

    • Compact the underlying ArrayBuffer.

      Returns void

    • Iterate through the vector from the tail-end, consuming each entry. Essentially, the same as running BigVector.pop in a loop until Function.length is zero.

      Returns IterableIterator<bigint>

      const vec = Vector.from([1, 2, 3], Uint8Array);
      for (const value of vec.consume()) {
      console.log(value); // 3, 2, 1
      }

      console.log(vec.length); // 0.