tix
v0.5.1
Published
Generate and track unique ids minimalistically
Downloads
18
Readme
#Tix
Tix is a unique id generator.
- Gives you unique ids
- Keeps track of whether a given id has been taken
- You can release a previously taken id
- Automatically expands backing store
- Uses bitmasks on an integer array for speed and awesomeness
var Tix = require('tix');
var ids = new Tix();
var id = ids.take(); // 0
var anotherId = ids.take(); // 1
ids.has(1); // true
ids.has(2); // false
var id = ids.take(); // 2
ids.has(2); // false
ids.release(1);
ids.has(1); // false
var id = ids.take() // 1
API
take() -> integer
returns the smallest positive integer not currently taken.
has() -> boolean
returns true
or false
depending on whether or not a given id currently taken.
release(id: integer) -> void
releases a taken id. Does nothing if the passed id hasn't been taken.