Created
December 21, 2018 14:58
-
-
Save gkucmierz/edb0b97585bbcfcb01e7fb984d4a266d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let BitArray = function(size) { | |
let arr = new Uint16Array(size >> 4); | |
let o = new Uint16Array(16); | |
let z = new Uint16Array(16); | |
for (let i = 0; i < 16; ++i) { | |
o[i] = 1 << i; | |
z[i] = o[i] ^ ((1<<16)-1); | |
} | |
return { | |
get: bit => { | |
let i = bit >> 4; | |
let b = bit - (i << 4); | |
return arr[i] & o[b]; | |
}, | |
set: (bit, value) => { | |
let i = bit >> 4; | |
let b = bit - (i << 4); | |
if (value) { | |
arr[i] = arr[i] | o[b]; | |
} else { | |
arr[i] = arr[i] & z[b]; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment