Skip to main content

BitArray

Defined in: js-api/src/u2core/bit-array.ts:7

A pure-JS bit array with the BitSet vocabulary: LSB-first Uint32Array words, bit i at words[i >>> 5] & (1 << (i & 31)), and the bits of the last word beyond length always zero — so equals is a word compare and DG.BitSet.fromBitArray reads the words as they are.

Constructors​

Constructor​

new BitArray(length, fill?): BitArray

Defined in: js-api/src/u2core/bit-array.ts:11

Parameters​

ParameterType
lengthnumber
fill?boolean

Returns​

BitArray

Constructor​

new BitArray(words, length): BitArray

Defined in: js-api/src/u2core/bit-array.ts:13

Adopts words (no copy); they must hold at least lengthInInts words.

Parameters​

ParameterType
wordsUint32Array
lengthnumber

Returns​

BitArray

Accessors​

allFalse​

Get Signature​

get allFalse(): boolean

Defined in: js-api/src/u2core/bit-array.ts:143

True if every bit is clear (also for an empty array).

Returns​

boolean


allTrue​

Get Signature​

get allTrue(): boolean

Defined in: js-api/src/u2core/bit-array.ts:141

True if every bit is set (also for an empty array).

Returns​

boolean


anyFalse​

Get Signature​

get anyFalse(): boolean

Defined in: js-api/src/u2core/bit-array.ts:139

True if at least one bit is clear.

Returns​

boolean


anyTrue​

Get Signature​

get anyTrue(): boolean

Defined in: js-api/src/u2core/bit-array.ts:137

True if at least one bit is set.

Returns​

boolean


falseCount​

Get Signature​

get falseCount(): number

Defined in: js-api/src/u2core/bit-array.ts:132

Number of clear bits.

Returns​

number


length​

Get Signature​

get length(): number

Defined in: js-api/src/u2core/bit-array.ts:99

Number of bits.

Returns​

number


lengthInInts​

Get Signature​

get lengthInInts(): number

Defined in: js-api/src/u2core/bit-array.ts:104

Number of 32-bit words backing the array.

Returns​

number


trueCount​

Get Signature​

get trueCount(): number

Defined in: js-api/src/u2core/bit-array.ts:127

Number of set bits.

Returns​

number

Methods​

and()​

and(other): this

Defined in: js-api/src/u2core/bit-array.ts:194

Bitwise AND with other (same length) in place.

Parameters​

ParameterType
otherBitArray

Returns​

this


andNot()​

andNot(other): this

Defined in: js-api/src/u2core/bit-array.ts:218

Clears the bits set in other (same length) in place.

Parameters​

ParameterType
otherBitArray

Returns​

this


andWithCountBits()​

andWithCountBits(other, value?): number

Defined in: js-api/src/u2core/bit-array.ts:226

The number of bits equal to value in this AND other, without modifying either.

Parameters​

ParameterTypeDefault value
otherBitArrayundefined
valuebooleantrue

Returns​

number


clone()​

clone(): BitArray

Defined in: js-api/src/u2core/bit-array.ts:146

A copy with the same bits.

Returns​

BitArray


copyFrom()​

copyFrom(other): this

Defined in: js-api/src/u2core/bit-array.ts:151

Copies the bits of other, which must have the same length.

Parameters​

ParameterType
otherBitArray

Returns​

this


equals()​

equals(other): boolean

Defined in: js-api/src/u2core/bit-array.ts:158

Same length and same bits.

Parameters​

ParameterType
otherBitArray

Returns​

boolean


findNext()​

findNext(i, x?): number

Defined in: js-api/src/u2core/bit-array.ts:239

The first index after i (pass -1 to start from the beginning) whose bit is x, or -1.

Parameters​

ParameterTypeDefault value
inumberundefined
xbooleantrue

Returns​

number


findPrev()​

findPrev(i, x?): number

Defined in: js-api/src/u2core/bit-array.ts:257

The last index before i (pass -1 to start from the end) whose bit is x, or -1.

Parameters​

ParameterTypeDefault value
inumberundefined
xbooleantrue

Returns​

number


get()​

get(i): boolean

Defined in: js-api/src/u2core/bit-array.ts:114

Gets the i-th bit; unchecked.

Parameters​

ParameterType
inumber

Returns​

boolean


getBuffer()​

getBuffer(): Uint32Array

Defined in: js-api/src/u2core/bit-array.ts:109

The live words; a direct write must keep the bits beyond length zero.

Returns​

Uint32Array


getRange()​

getRange(from, to): BitArray

Defined in: js-api/src/u2core/bit-array.ts:345

A copy of the bits in [from, to).

Parameters​

ParameterType
fromnumber
tonumber

Returns​

BitArray


getSelectedIndexes()​

getSelectedIndexes(): Int32Array

Defined in: js-api/src/u2core/bit-array.ts:273

Indexes of all set bits.

Returns​

Int32Array


init()​

init(f): this

Defined in: js-api/src/u2core/bit-array.ts:171

Sets the i-th bit to f(i) for every i.

Parameters​

ParameterType
fBitPredicate

Returns​

this


invert()​

invert(): this

Defined in: js-api/src/u2core/bit-array.ts:187

Flips every bit.

Returns​

this


or()​

or(other): this

Defined in: js-api/src/u2core/bit-array.ts:202

Bitwise OR with other (same length) in place.

Parameters​

ParameterType
otherBitArray

Returns​

this


removeAt()​

removeAt(pos, n?): void

Defined in: js-api/src/u2core/bit-array.ts:306

Removes n bits starting at pos, shifting the following bits down.

Parameters​

ParameterTypeDefault value
posnumberundefined
nnumber1

Returns​

void


set()​

set(i, x): void

Defined in: js-api/src/u2core/bit-array.ts:119

Sets the i-th bit; unchecked.

Parameters​

ParameterType
inumber
xboolean

Returns​

void


setAll()​

setAll(x): this

Defined in: js-api/src/u2core/bit-array.ts:181

Sets every bit to x.

Parameters​

ParameterType
xboolean

Returns​

this


setLength()​

setLength(n): void

Defined in: js-api/src/u2core/bit-array.ts:292

Resizes to n bits, the added ones false; reallocates to exactly the words needed.

Parameters​

ParameterType
nnumber

Returns​

void


setRange()​

setRange(from, to, x): this

Defined in: js-api/src/u2core/bit-array.ts:316

Sets the bits in [from, to) to x.

Parameters​

ParameterType
fromnumber
tonumber
xboolean

Returns​

this


toBinaryString()​

toBinaryString(): string

Defined in: js-api/src/u2core/bit-array.ts:369

The bits as a string of 0 and 1, index 0 first.

Returns​

string


toString()​

toString(): string

Defined in: js-api/src/u2core/bit-array.ts:361

The bits as a string of '0' and '1' characters, like '0110'.

Returns​

string


trueIndexes()​

trueIndexes(): IterableIterator<number>

Defined in: js-api/src/u2core/bit-array.ts:284

Iterates the indexes of the set bits in ascending order.

Returns​

IterableIterator<number>


xor()​

xor(other): this

Defined in: js-api/src/u2core/bit-array.ts:210

Bitwise XOR with other (same length) in place.

Parameters​

ParameterType
otherBitArray

Returns​

this


create()​

static create(length, f?): BitArray

Defined in: js-api/src/u2core/bit-array.ts:65

A bit array of length bits, the i-th one f(i) when f is given.

Parameters​

ParameterType
lengthnumber
f?BitPredicate | null

Returns​

BitArray


fromBytes()​

static fromBytes(buffer, bitLength?): BitArray

Defined in: js-api/src/u2core/bit-array.ts:76

A copy of the little-endian bytes; bitLength defaults to all of them.

Parameters​

ParameterType
bufferArrayBuffer | ArrayBufferView<ArrayBufferLike>
bitLength?number

Returns​

BitArray


fromString()​

static fromString(zerosOnes): BitArray

Defined in: js-api/src/u2core/bit-array.ts:71

From a string of '0' and '1' characters, like '0110'.

Parameters​

ParameterType
zerosOnesstring

Returns​

BitArray


fromUint32Array()​

static fromUint32Array(length, words): BitArray

Defined in: js-api/src/u2core/bit-array.ts:94

Adopts words (no copy), like the constructor.

Parameters​

ParameterType
lengthnumber
wordsUint32Array

Returns​

BitArray