Skip to main content

BitArray

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

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:10

Parameters

ParameterType
lengthnumber
fill?boolean

Returns

BitArray

Constructor

new BitArray(words, length): BitArray

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

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:134

Returns

boolean


allTrue

Get Signature

get allTrue(): boolean

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

Returns

boolean


anyFalse

Get Signature

get anyFalse(): boolean

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

Returns

boolean


anyTrue

Get Signature

get anyTrue(): boolean

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

Returns

boolean


falseCount

Get Signature

get falseCount(): number

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

Returns

number


length

Get Signature

get length(): number

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

Returns

number


lengthInInts

Get Signature

get lengthInInts(): number

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

Returns

number


trueCount

Get Signature

get trueCount(): number

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

Returns

number

Methods

and()

and(other): this

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

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:206

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:214

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:136

Returns

BitArray


copyFrom()

copyFrom(other): this

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

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:148

Same length and same bits.

Parameters

ParameterType
otherBitArray

Returns

boolean


findNext()

findNext(i, x?): number

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

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:245

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:111

Gets the i-th bit; unchecked.

Parameters

ParameterType
inumber

Returns

boolean


getBuffer()

getBuffer(): Uint32Array

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

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:333

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:261

Indexes of all set bits.

Returns

Int32Array


init()

init(f): this

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

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:175

Returns

this


or()

or(other): this

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

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:294

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:116

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:170

Parameters

ParameterType
xboolean

Returns

this


setLength()

setLength(n): void

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

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:304

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:356

Returns

string


toString()

toString(): string

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

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:272

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:198

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:64

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:75

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:70

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:93

Adopts words (no copy), like the constructor.

Parameters

ParameterType
lengthnumber
wordsUint32Array

Returns

BitArray