Class: BooleanSet

BooleanSet(stateOrObj)

Allows an infinite array of booleans to be set to true or false using ranges to efficiently compress consecutive values. TODO: maximize compatibility with existing apis, might want end indices to be exclusive TODO: optimize ranges using arrays and single numbers TODO: don't set flipped by default TODO: split this off as its own project, submodule?

Constructor

new BooleanSet(stateOrObj)

Constructs a BooleanSet.
Parameters:
Name Type Description
stateOrObj is a state to initialize by reference, an existing BooleanSet to deep copy, or defaults to a cleared state
Source:

Methods

allSet(val, start, end) → {boolean}

Indicates if all booleans in a range are set to a given value.
Parameters:
Name Type Description
val boolean is the value to test in the range
start number is the start of the range, inclusive (defaults to 0)
end number is the end of the range, inclusive (defaults to infinity)
Source:
Returns:
is true if all booleans in the range are the given value, false otherwise
Type
boolean

anySet(val, start, end) → {boolean}

Indicates if any booleans in a range are set to a given value.
Parameters:
Name Type Description
val boolean is the value to test in the range
start number is the start of the range, inclusive (defaults to 0)
end number is the end of the range, inclusive (defaults to infinity)
Source:
Returns:
is true if any booleans in the range are the given value, false otherwise
Type
boolean

clear() → {BooleanSet}

Sets all booleans to false.
Source:
Returns:
is this instance
Type
BooleanSet

copy() → {BooleanSet}

Copies this BooleanSet to a new one.
Source:
Returns:
is a copy of this instance
Type
BooleanSet

flip(idx) → {BooleanSet}

Flips one or all booleans.
Parameters:
Name Type Description
idx number is the index to flip, flips all if not provided
Source:
Returns:
is this instance
Type
BooleanSet

flipRange(start, end) → {BooleanSet}

Flips booleans in a range.
Parameters:
Name Type Description
start is the start of the range (defaults to 0)
end is the end of the range (defaults to infinit)
Source:
Returns:
is this instance
Type
BooleanSet

get(idx) → {boolean}

Gets the boolean value at a given index.
Parameters:
Name Type Description
idx number is the index of the value to get
Source:
Returns:
the value at the index
Type
boolean

getFirst(val, start, end) → {number}

Gets the first index in a range with the given value.
Parameters:
Name Type Description
val boolean is the value to get the first index of
start is the start of the range, inclusive (defaults to 0)
end is the end of the range, inclusive (defaults to infinity)
Source:
Returns:
is the first index in the range with the value, null if none found
Type
number

getLast(val, start, end) → {number}

Gets the last index in a range with the given value.
Parameters:
Name Type Description
val boolean is the value to get the last index of
start is the start of the range, inclusive (defaults to 0)
end is the end of the range, inclusive (defaults to infinity)
Source:
Returns:
is the last index in the range with the value, null if none found, undefined if infinity
Type
number

getState() → {Object}

Returns the internal state of this set.
Source:
Returns:
with internal state.
Type
Object

length() → {number}

Returns the index of the first boolean that is the same as infinity. Returns the index of the last boolean before all remaining booleans are infinitely false or true (depending on if flip() was called which flips infinity).
Source:
Returns:
is the last set boolean before the remaining are infinitely true or false
Type
number

set(val, idx) → {BooleanSet}

Sets one or all booleans.
Parameters:
Name Type Description
val boolean is the boolean value to set
idx number is the index of the value to set, sets all if not provided
Source:
Returns:
is this instance
Type
BooleanSet

setRange(val, start, end) → {BooleanSet}

Sets booleans in a range.
Parameters:
Name Type Description
val boolean is the boolean value to set in the range
start number is the start of the range (defaults to 0)
end number is the end of the range (defaults to infinity)
Source:
Returns:
is this instance
Type
BooleanSet

toArray(start, is) → {Array.<boolean>}

Converts the given range to an array.
Parameters:
Name Type Description
start number is the start index of the range, inclusive (defaults to 0)
is number the end index of the range, exclusive (defaults to length())
Source:
Returns:
is an array representation of the given range
Type
Array.<boolean>