@icazemier/gibbons
    Preparing search index...

    Class Gibbon

    A Gibbon

    allocate this Gibbon with some working memory

    Index

    Constructors

    Properties

    arrayBuffer: ArrayBuffer
    dataView: DataView

    Methods

    • Set value for a bit on position

      Parameters

      • position: number

        unsigned integer value

      • Optionalon: boolean = false

        Optional set true or false (default : false)

      Returns Gibbon

      • Return itself for chaining purposes
      const gibbon = Gibbon.create(2);
      gibbon.changePosition(1, true);

      gibbon.isPosition(1); // returns true
    • Set bit: false according to integer position Note: Starting from 1

      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 string | Buffer<ArrayBufferLike>

    • Compare two gibbon instances on data contents

      Parameters

      • gibbon: Gibbon

        instance of a Gibbon

      Returns boolean

      if instance (or contents) are the same

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

      Returns number[]

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


      // 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]
    • Compare 2 gibbons and see if this gibbon shares all given bits

      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.

      Parameters

      • positionArray: number[] = []

        containing signed integer values (representing bit positions)

      Returns boolean

      true when all positions correspondent to the given indexes

       // 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
       // 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

      if positionArray is not an instance of array

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

      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.

      Parameters

      • positionArray: number[] = []

        containing signed integer values (representing bit positions)

      Returns boolean

      true when one of these positions correspond

       // 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
       // 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

      if positionArray is not an instance of array

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

      Parameters

      • position: number

        unsigned integer value

      Returns boolean

      if membership is set

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

      gibbon.isPosition(1); // returns true
    • Able to manipulate bits according to an array of signed integers

      Parameters

      • positionArray: number[] = []

        Array with integer values starting from 1.

      Returns Gibbon

      • For chaining purposes
       // Set 2 bit positions to logical '1'
      const gibbon = Gibbon.create(2);
      gibbon.setAllFromPositions([1, 2]);
      gibbon.hasAllFromPositions([1, 2]); // returns true
       // 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

      When out of bounds

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

      Parameters

      • position: number

        unsigned integer value

      Returns Gibbon

      • For chaining purposes

      Position can't exceed data view bounds.

    • Converts this Gibbon instance to a Buffer

      Returns Buffer

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

      Parameters

      • position: number

        unsigned integer value

      Returns Gibbon

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

      gibbon.isPosition(1); // true
    • Convert the whole ArrayBuffer to a string
      (Hint: Could be used to store a gibbon in persistent storage as a encoded string)

      Returns string

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

      Parameters

      • positionArray: number[] = []

        Array with integer values starting from 1.

      Returns Gibbon

      • For chaining purposes
       // 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
       // 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

      if positionArray is not an instance of array

    • Creates a new empty Gibbon from a given byte size

      Parameters

      • byteSize: number

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

      Returns Gibbon

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

      Parameters

      • data: string | Buffer<ArrayBufferLike>

      Returns Gibbon

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

      Parameters

      • gibbonString: string

        To be decoded to a Gibbon

      Returns Gibbon

      • new instance of a Gibbon