BitList
An implementation of a bit array (also known as bit vector, bit mask or bit set), which allows the set to grow or shrink
as necessary, and allows inserting or removing values from arbitrary positions in the list.
Install
npm install bitlist
Usage
var BitList = require('bitlist');
var list = new BitList();
list.insert(0, true);
list.insert(1, false);
list.insert(0, false);
list.insert(2, true);
list.get(0);
list.get(1);
list.remove(0);
list.size;
var otherList = new BitList([false, true, true]);
list.applyAnd([otherList]);
API
-
get(index)
- Get the value at the given index.
-
set(index, value)
- Update the value at the given index.
-
insert(index, value)
- Insert a new value into the list at the given position.
-
remove(index)
- Remove a value from the list.
-
applyAnd(lists)
- Apply one or more other BitLists to the current one, using AND operations (treats each as a mask).
-
clearRange(lowIndex, highIndex)
- Set a range of values to false. Indexes are inclusive.
-
clone()
- Create a new BitList which has the same values as this one.
-
getIndexes(matchValue)
-
Turn the BitList into an array of indexes which have the given value.
[1,0,1,1,0].getIndexes(false) -> [1, 4]
[1,0,1,1,0].getIndexes(true) -> [0, 2, 3]
-
countValuesInRange(value, lowIndex, highIndex)
- Count the number of items in the given range which have the given value. Indexes are inclusive.
License
The MIT License (MIT)
Copyright (c) 2015 SoundCloud
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.