A Gibbon

Param

allocate this Gibbon with some working memory

Hierarchy

  • Gibbon

Constructors

  • Parameters

    • arrayBuffer: ArrayBuffer

    Returns Gibbon

Properties

arrayBuffer: ArrayBuffer
dataView: DataView

Methods

  • Set value for a bit on position

    Example

    const gibbon = Gibbon.create(2);
    gibbon.changePosition(1, true);

    gibbon.isPosition(1); // returns true

    Returns

    • Return itself for chaining purposes

    Parameters

    • position: number

      unsigned integer value

    • Optional on: boolean = false

      Optional set true or false (default : false)

    Returns Gibbon

  • Set bit: false according to integer position Note: Starting from 1

    Returns

    Parameters

    • position: number

      unsigned integer value

    Returns Gibbon

  • Depending on the GIBBONS_ENCODE_FROM_TO_STRING environment variable if converts this Gibbon to a string or Buffer

    Returns

    Returns string | Buffer

  • Compare two gibbon instances on data contents

    Returns

    if instance (or contents) are the same

    Parameters

    • gibbon: Gibbon

      instance of a Gibbon

    Returns boolean

  • This method analyzes every bit value in this gibbon and creates the corresponding
    position array where bits are logical true.

    Example


    // Initialize a Gibbon (2 bytes)
    const gibbon = Gibbon.create(2);

    // Pre set some bit positions
    gibbon.setPosition(1)
    .setPosition(2)
    .setPosition(3)
    .setPosition(4)
    .setPosition(5)
    .setPosition(6)
    .setPosition(7)
    .setPosition(8)
    .setPosition(10);

    gibbon.getPositionsArray(); // returns: [1, 2, 3, 4, 5, 6, 7, 8, 10]

    Returns

    Which contains bit positions from this gibbon, which are logical set to true

    Returns number[]

  • Compare 2 gibbons and see if this gibbon shares all given bits

    Returns

    Parameters

    Returns boolean

  • Compares all given positions

    • A positive position means this position should be set logical '1'
    • A negative position means this position should be set logical '0'

    When one wants to check on bit positions outside the memory bounds (dataViewBounds),
    method wil return early with false.

    Example

     // Initialize a gibbon with 2 bytes
    const gibbon = Gibbon.create(2);
    // Set 2 bit positions to logical '1'
    gibbon.setPosition(1).setPosition(2);

    gibbon.hasAllFromPositions([1, 2]); // true

    Example

     // Set 2 bit positions to logical '1' then the first bit position back to '0'
    const gibbon = Gibbon.create(2);
    gibbon.setPosition(1).setPosition(2).togglePosition(1);

    gibbon.hasAllFromPositions([-1, 2]); // true

    Returns

    true when all positions correspondent to the given indexes

    Throws

    if positionArray is not an instance of array

    Parameters

    • positionArray: number[] = []

      containing signed integer values (representing bit positions)

    Returns boolean

  • Compare 2 gibbons and see if this gibbon has at least one bit alike

    Returns

    Parameters

    Returns boolean

  • Compares the given positions

    • A positive position means this position should be set logical '1'
    • A negative position means this position should be set logical '0'

    When any of the positions conforms to logical '1' (true), we return true early.

    When one wants to check on bit positions outside the memory bounds (dataViewBounds),
    method wil return early with false.

    Example

     // Initialize a gibbon with 2 bytes
    const gibbon = Gibbon.create(2);
    // Set 3 bit positions to logical '1'
    gibbon.setPosition(1).setPosition(2).setPosition(10);

    gibbon.hasAnyFromPositions([1, 9]); // true

    Example

     // Set 2 bit positions to logical '1' then the first bit position back to '0'
    const gibbon = Gibbon.create(2);
    gibbon.setPosition(1).setPosition(2),togglePosition(1);

    gibbon.hasAllFromPositions([-1, 100]); // true

    Returns

    true when one of these positions correspond

    Throws

    if positionArray is not an instance of array

    Parameters

    • positionArray: number[] = []

      containing signed integer values (representing bit positions)

    Returns boolean

  • Checks if a value is true or false on a specific position

    Example

    const gibbon = Gibbon.create(2);
    gibbon.setPosition(1);

    gibbon.isPosition(1); // returns true

    Returns

    if membership is set

    Parameters

    • position: number

      unsigned integer value

    Returns boolean

  • Able to manipulate bits according to an array of signed integers

    Example

     // Set 2 bit positions to logical '1'
    const gibbon = Gibbon.create(2);
    gibbon.setAllFromPositions([1, 2]);
    gibbon.hasAllFromPositions([1, 2]); // returns true

    Example

     // Set 1 bit positions to logical '1' and the second to '0'
    const gibbon = Gibbon.create(2);
    gibbon.setAllFromPositions([1, -2]);
    gibbon.hasAllFromPositions([1]); // returns true

    Returns

    • For chaining purposes

    Throws

    When out of bounds

    Parameters

    • positionArray: number[] = []

      Array with integer values starting from 1.

    Returns Gibbon

  • Set bit: true according to integer position in the Gibbon
    Note: Starting from 1

    Throws

    Position can't exceed data view bounds.

    Returns

    • For chaining purposes

    Parameters

    • position: number

      unsigned integer value

    Returns Gibbon

  • Converts this Gibbon instance to a Buffer

    Returns

    Returns Buffer

  • Convert the whole ArrayBuffer to a string
    (Hint: Could be used to store a gibbon in persistent storage as a encoded string)

    Returns

    • Encoded string

    Returns string

  • Toggle bit value true => false, false => true

    Example

    const gibbon = Gibbon.create(2);
    gibbon.changePosition(1, true);

    gibbon.isPosition(1); // true

    Returns

    Parameters

    • position: number

      unsigned integer value

    Returns Gibbon

  • Able to manipulate bits according to an array of signed integers (opposite of setAllFromPositions)

    Example

     // Set 2 bit positions to logical '0'
    const gibbon = Gibbon.create(2);
    gibbon.unsetAllFromPositions([1, 2]);
    gibbon.hasAllFromPositions([1, 2]); // returns false
    gibbon.hasAllFromPositions([-1, -2]); // returns true

    Example

     // Set 1 bit positions to logical '0' and the second to '1'
    const gibbon = Gibbon.create(2);
    gibbon.setAllFromPositions([1, -2]);
    gibbon.hasAllFromPositions([2]); // returns true

    Returns

    • For chaining purposes

    Throws

    if positionArray is not an instance of array

    Parameters

    • positionArray: number[] = []

      Array with integer values starting from 1.

    Returns Gibbon

  • Creates a new empty Gibbon from a given byte size

    Returns

    • new instance of a Gibbon

    Parameters

    • byteSize: number

      Allocate this Gibbon with a unsigned integer value (size in bytes)

    Returns Gibbon

  • Accepts a string of Buffer to create a new Gibbon instance

    Returns

    Parameters

    • data: string | Buffer

    Returns Gibbon

  • Class method to create a new Gibbon from a string
    (Hint: Could be used to retrieve from persistent storage)

    Returns

    • new instance of a Gibbon

    Parameters

    • gibbonString: string

      To be decoded to a Gibbon

    Returns Gibbon

Generated using TypeDoc