Files
djhackersdev_minime/src/idz/encoder/_bitmap.ts
T
Tau 9c06d6635f idz: Rename encoder funcs
Avoid name collision between nouns and verbs.
2019-11-06 17:28:30 -05:00

13 lines
283 B
TypeScript

export function encodeBitmap(items: Set<number>, nbytes: number): Buffer {
const buf = Buffer.alloc(nbytes);
for (const item of items) {
const byte = (item / 8) | 0;
const bit = item % 8;
buf.writeUInt8(buf.readUInt8(byte) | (1 << bit), byte);
}
return buf;
}