Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BitSet

Fast JS BitSet implementation. Beyond 32bit restrictions.

Hierarchy

  • BitSet

Index

Constructors

constructor

  • new BitSet(indices_length?: Iterable<number> | number): BitSet
  • BitSet constructor.

    Parameters

    • Default value indices_length: Iterable<number> | number = WORD_SIZE

      Length for the underlying bitvector or an Iterable with indices.

    Returns BitSet

    a new BitSet.

Properties

__@toStringTag

__@toStringTag: string = "BitSet"

Custom name for Object.prototype.toString.call(bitset) === [object BitSet]

Private _length

_length: number

words

words: Int32Array

Array of 32bit words.

Static __@species

__@species: BitSet = BitSet

The species of the BitSet. Which is just the BitSet constructor.

Accessors

cardinality

  • get cardinality(): number
  • set cardinality(v: number): void
  • Getter for the cardinality of the set. In case of a set it will return a warning.

    aliases:

    size

    readonly
    type

    number

    Returns number

  • Getter for the cardinality of the set. In case of a set it will return a warning.

    Parameters

    • v: number

    Returns void

length

  • get length(): number
  • set length(v: number): void
  • Getter for the length of the underlying bitvector. In case of a set it will return a warning.

    Returns number

  • Getter for the length of the underlying bitvector. In case of a set it will return a warning.

    Parameters

    • v: number

    Returns void

size

  • get size(): number
  • set size(v: number): void

Methods

And

Complement

  • Calculates the inverse of the set. Any trailing bits outside the length bound will be set to 0. The result will be a new instance of a BitSet.

    Returns BitSet

    a new BitSet of the complement.

Difference

  • Calculates the difference between 2 bitsets. The result will be a new instance of BitSet.

    Parameters

    • bitset: BitSet

      The bit set to subtract from the current one.

    Returns BitSet

    a new BitSet of the difference.

Exclusion

  • Calculates the exclusion/symmetric difference between to bitsets. The result is a new instance of BitSet.

    aliases:

    SymmetricDifference, XOR

    Parameters

    • bitset: BitSet

      The bitset to calculate the symmetric difference with.

    Returns BitSet

    a new BitSet of the exclusion.

Intersection

  • Calculates the intersection between two bitsets. The result is a new instance of BitSet.

    aliases:

    And

    Parameters

    • bitset: BitSet

      The bitset to calculate the intersection with.

    Returns BitSet

    a new bitset intersection.

Or

SymmetricDifference

Union

  • Calculates the union between 2 bitsets. The result is a new BitSet.

    aliases:

    Or

    Parameters

    • bitset: BitSet

      Bitset to calculate the union with.

    Returns BitSet

    a new BitSet of the union of the two bitsets.

XOR

__@iterator

  • __@iterator(): IterableIterator<number>
  • Prototype Symbol.iterator to make BitSet iterable. Returns a new Iterator object that contains the indices in the BitSet object.

    Returns IterableIterator<number>

    iterable iterator containing the indices.

add

  • add(...indices: number[]): BitSet
  • Adds numbers(indices) to the set. It will resize the set in case the index falls out of bounds.

    Parameters

    • Rest ...indices: number[]

      Indices/numbers to add to the set.

    Returns BitSet

    this.

and

clear

clone

complement

  • Calculates the inverse of the set. Any trailing bits outside the length bound will be set to 0.

    Returns BitSet

    this.

contains

  • contains(mask: BitSet): boolean
  • Calculates if the bitset contains a certain bitset. In bitmask terms it will calculate if a bitmask fits a bitset.

    aliases:

    fits

    Parameters

    • mask: BitSet

      Tests if a bitset mask fits. i.e. subset to test containment.

    Returns boolean

    a boolean indicating if the mask fits the bitset (i.e. is a subset).

del

  • del(...indices: number[]): BitSet

difference

  • Calculates the difference between 2 bitsets. The result is stored in this.

    Parameters

    • bitset: BitSet

      The bitset to subtract from the current one.

    Returns BitSet

    this.

each

  • each(cb: function, ctx?: object): boolean
  • Iterates over the set bits and calls the callback function with: value=1, index, this. Can be broken prematurely by returning false.

    aliases:

    forEach

    Parameters

    • cb: function

      Callback function to be called on each bit.

        • (value: number, index: number, bitset: BitSet): any | boolean
        • Parameters

          • value: number
          • index: number
          • bitset: BitSet

          Returns any | boolean

    • Optional ctx: object

      Context to be called upon the callback function.

    Returns boolean

    a boolean indicating if the loop finished completely=true or was broken=false.

eachAll

  • eachAll(cb: function, ctx?: object): boolean
  • Iterates over all bits and calls the callback function with: value, index, this. Can be broken prematurely by returning false.

    aliases:

    forEachAll

    Parameters

    • cb: function

      Callback function o be called on each bit.

        • (value: number, index: number, bitset: BitSet): any | boolean
        • Parameters

          • value: number
          • index: number
          • bitset: BitSet

          Returns any | boolean

    • Optional ctx: object

      Context to be called upon the callback function.

    Returns boolean

    a boolean indicating if the loop finished completely=true or was broken=false.

entries

  • entries(): IterableIterator<[number, number]>
  • Returns a new Iterator object that contains an array of [index, index] for each element in the BitSet object. This is kept similar to the Map object, so that each entry has the same value for its key and value here.

    Returns IterableIterator<[number, number]>

    an iterable iterator yielding set indices [index, index].

equals

  • equals(bitset: BitSet): boolean
  • Tests if 2 bitsets are equal.

    Parameters

    • bitset: BitSet

      Bitset to compare to this.

    Returns boolean

    a boolean indicating if the the 2 bitsets are equal.

exclusion

  • Calculates the exclusion/symmetric difference between to bitsets. The result is stored in this.

    aliases:

    symmetricDifference, xor

    Parameters

    • bitset: BitSet

      The bitset to calculate the symmetric difference with.

    Returns BitSet

    this.

fits

flip

  • Flips a bit in the bitset. In case index will fall out of bounds the bitset is enlarged.

    Parameters

    • index: number

      Index of the bit to be flipped.

    Returns BitSet

    this.

forEach

  • forEach(cb: function, ctx?: object): boolean
  • Alias of each

    Parameters

    • cb: function
        • (value: number, index: number, bitset: BitSet): any | boolean
        • Parameters

          • value: number
          • index: number
          • bitset: BitSet

          Returns any | boolean

    • Optional ctx: object

    Returns boolean

forEachAll

  • forEachAll(cb: function, ctx?: object): boolean
  • Alias of eachAll

    Parameters

    • cb: function
        • (value: number, index: number, bitset: BitSet): any | boolean
        • Parameters

          • value: number
          • index: number
          • bitset: BitSet

          Returns any | boolean

    • Optional ctx: object

    Returns boolean

get

  • get(index: number): number
  • Gets a specific bit from the bitset.

    Parameters

    • index: number

      Index of the bit to get.

    Returns number

    the value of the bit at the given index.

has

  • has(index: number): boolean
  • Checks is the bitsets has a value/index.

    aliases:

    isMember

    Parameters

    • index: number

      The index/value to check membership for.

    Returns boolean

    a boolean indicating if the bitset has the vale/index.

init

  • init(indices_length?: Iterable<number> | number): BitSet
  • Initializes the BitSet. Useful for reinitialization in case of pooling.

    Parameters

    • Default value indices_length: Iterable<number> | number = WORD_SIZE

      Length for the underlying bitvector or an iterable object with indices.

    Returns BitSet

    this.

intersection

  • Calculates the intersection between two bitsets. The result is stored in this.

    aliases:

    and

    Parameters

    • bitset: BitSet

      The bitset to calculate the intersection with.

    Returns BitSet

    this.

intersects

  • intersects(bitset: BitSet): boolean
  • Calculates if two bitsets intersect.

    Parameters

    • bitset: BitSet

      The bitset to check intersection with.

    Returns boolean

    a boolean indicating if the two bitsets intersects.

isContainedIn

  • isContainedIn(bitset: BitSet): boolean

isEmpty

  • isEmpty(): boolean
  • Returns if a set is empty i.e. all words are 0.

    Returns boolean

    a boolean indicating that the set is empty.

isMember

  • isMember(index: number): boolean
  • Alias of has

    Parameters

    • index: number

    Returns boolean

isSubsetOf

  • isSubsetOf(bitset: BitSet): boolean
  • Checks if a bitset is contained in another.

    aliases:

    isContainedIn

    Parameters

    • bitset: BitSet

      BitSet to check for containment.

    Returns boolean

    a boolean indicating if this is contained in bitset.

keys

  • keys(): IterableIterator<number>
  • Returns a new Iterator object that contains the indices of the BitSet.

    Returns IterableIterator<number>

    iterable iterator containing set indices.

lsb

  • lsb(): number

max

  • max(): number
  • Returns the max index in a set.

    aliases:

    msb

    Returns number

    the max number/index in the set.

min

  • min(): number
  • Returns the minimum index in a set.

    aliases

    lsb

    Returns number

    the minimum number/index in the set.

msb

  • msb(): number

or

remove

  • remove(...indices: number[]): BitSet
  • Removes indices/numbers from the bitset.

    alias

    del

    Parameters

    • Rest ...indices: number[]

      The indices/numbers to be removed.

    Returns BitSet

    this.

resize

  • resize(length: number): BitSet
  • Resizes the underlying bitvector to a specific length. Will trim any trailing bits in case length is smaller than the current length.

    Parameters

    • length: number

      The new length.

    Returns BitSet

    the resized bitset.

set

  • set(index: number, val?: number): BitSet
  • Adds a number(index) to the set. It will resize the set in case the index falls out of bounds.

    Parameters

    • index: number

      Index/number to add to the set.

    • Default value val: number = ONE

      Value (0|1) to set.

    Returns BitSet

    this.

stringify

  • stringify(mode?: number): string

symmetricDifference

toArray

  • toArray(type?: number): number[] | Uint8Array | Uint16Array | Uint32Array
  • Outputs the set as an array.

    Parameters

    • Optional type: number

      Type for the array Uint(8|16|32)Array.

    Returns number[] | Uint8Array | Uint16Array | Uint32Array

    an array representing the bitset.

toBitArray

  • toBitArray(type?: number): number[] | Uint8Array | Uint16Array | Uint32Array
  • Outputs the underlying bitvector as an array, starting with the least significant bits.

    Parameters

    • Optional type: number

      Type for the array Uint(8|16|32)Array.

    Returns number[] | Uint8Array | Uint16Array | Uint32Array

    an bit array representation of the bitset.

toBitString

  • toBitString(mode?: number): string
  • Outputs the underlying bitvector as a bitstring, starting with the most significant bit.

    Parameters

    • Optional mode: number

      Mode for stringification. -1 is used to display the full string including trailing bits.

    Returns string

    the stringified bitvector.

toBooleanArray

  • toBooleanArray(): boolean[]
  • Outputs the underlying bitvector as a boolean array, starting with the least significant bits.

    Returns boolean[]

    a boolean array representing the bitset.

toString

  • toString(mode?: number): string
  • Will output a string version of the bitset or bitstring.

    aliases:

    stringify

    Parameters

    • Optional mode: number

      Mode of toString. undefined=bitset | 2=bitstring | -1=full bitstring.

    Returns string

    stringified version of the bitset.

trim

  • Trims the bitset to the most significant bit to save space.

    Returns BitSet

    this.

trimTrailingBits

  • Trims (sets to zero) any trailing bits that fall out of this._length but within this.words.length*WORD_SIZE. Assumes this.length is somewhere in the last word.

    Returns BitSet

    this.

union

  • Calculates the union between 2 bitsets. The result is stored in this.

    aliases:

    or

    Parameters

    • bitset: BitSet

      Bitset to calculate the union with.

    Returns BitSet

    the union of the two bitsets.

values

  • values(): IterableIterator<number>
  • Returns a new Iterator object that contains the indices of the BitSet.

    Returns IterableIterator<number>

    iterable iterator containing yielding the indices.

xor

Static create

  • create(indices_length?: Iterable<number> | number): BitSet
  • Easy create method avoiding ugly 'new' keywords.

    aliases:

    spawn

    Parameters

    • Default value indices_length: Iterable<number> | number = WORD_SIZE

      Length for the underlying bitvector or an iterable object with indices.

    Returns BitSet

    a new BitSet.

Static hammingWeight

  • hammingWeight(w: number): number
  • Calculate the hamming weight i.e. the number of ones in a bitstring/word.

    aliases:

    popCount

    Parameters

    • w: number

      Word to get the number of set bits from.

    Returns number

    the number of set bits in the word.

Static lsb

  • lsb(w: number): number
  • Returns the least significant bit in a word. Returns 32 in case the word is 0.

    Parameters

    • w: number

      The word to get the least significant bit from.

    Returns number

    the least significant bit in w.

Static msb

  • msb(w: number): number
  • Returns the most significant bit in a word.

    Parameters

    • w: number

      the word to get the most significant bit from.

    Returns number

    the most significant bit in w.

Static popCount

  • popCount(w: number): number

Static spawn

  • spawn(indices_length?: Iterable<number> | number): BitSet
  • Alias of create

    Parameters

    • Default value indices_length: Iterable<number> | number = WORD_SIZE

    Returns BitSet

Object literals

Static info

info: object

Info object to hold general module information.

description

description: string = "Fast JS BitSet implementation. Beyond 32bit restrictions."

name

name: string = "cell-bitset"

url

url: string = "https://github.com/unnoon/cell-bitset"

version

version: string = "/*?= VERSION */"

Generated using TypeDoc