UNPKG

734 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * Use typed arrays if we can
8 */
9
10var FastArray = typeof Uint32Array === 'undefined' ? Array : Uint32Array;
11
12/**
13 * Bit vector
14 */
15
16function createBv(sizeInBits) {
17 return new FastArray(Math.ceil(sizeInBits / 32));
18}
19
20function setBit(v, idx) {
21 var r = idx % 32;
22 var pos = (idx - r) / 32;
23
24 v[pos] |= 1 << r;
25}
26
27function clearBit(v, idx) {
28 var r = idx % 32;
29 var pos = (idx - r) / 32;
30
31 v[pos] &= ~(1 << r);
32}
33
34function getBit(v, idx) {
35 var r = idx % 32;
36 var pos = (idx - r) / 32;
37
38 return !!(v[pos] & 1 << r);
39}
40
41/**
42 * Exports
43 */
44
45exports.default = {
46 createBv: createBv,
47 setBit: setBit,
48 clearBit: clearBit,
49 getBit: getBit
50};
\No newline at end of file