Skip to content

Instantly share code, notes, and snippets.

View NateTheGreatt's full-sized avatar

Nate Martin NateTheGreatt

View GitHub Profile
@NateTheGreatt
NateTheGreatt / Bitmask.js
Created August 2, 2020 14:58
Infinite Bitmask in Javascript
export const Bitmask = (length, type=Uint32Array) => {
const bitsPerMask = type.BYTES_PER_ELEMENT * 8,
totalBytes = Math.ceil(length / bitsPerMask) * type.BYTES_PER_ELEMENT,
masks = new type(new SharedArrayBuffer(totalBytes))
const on = (i) => {
const masksIndex = Math.floor(i/bitsPerMask)
const index = i - bitsPerMask*masksIndex
const bitflag = Math.pow(2,index)