extensible-bit-vector
An extensible bit-vector implementation for Javascript.
Usage
; ;vector.set2;vector.set7;vector.set31; ; // true; // false; // true vector.set42; // automatically grows bitvector to fit.vector.clear2;vector.clear3; ; // false; // false ; // compressed bitvector in Base64 format// Store str in db here; // re-hydrate bitvector from database. ; // false; // true
You get the idea.
This is a bitvector that only works on Node, not the browser. The reason is that it relies on the Node Buffer class for serialization to and from strings. If you never do any serialization then it will work in the browser, but I don't recommend it.
In memory, the data is stored as a Uint8Array vector, and every 8 bits are stored as each byte. I would have used Uint32Array but it's much easier to convert to and from Base64 using Uint8Array.
The serialization method is designed to produce an optimized storage implementation of the bitvector, using as little memory as possible while still being storable in your average document database. I'm sure there are better ways to optimize the storage, but none are going to be as compatible as this.