weak-index
v0.1.0
Published
weakly assign ids to tuples of objects
Downloads
2
Readme
WeakIndex
WeakIndex allows you to weakly assign unique ids to tuples of objects.
You should provide a hash function that takes an array of integers to a primitive data type. If you do not provide a hash function, WeakIndex will use the Cantor tuple function, which works well for small numbers of indexes.
npm i weak-index
example
const hash = require('object-hash')
const { WeakIndex } = require('weak-index')
const ids = new WeakIndex(hash)
const o1 = {}, o2 = {}, o3 = {}
console.log(ids.put(o1))
console.log(ids.put(o1, o2))
console.log(ids.put(o2, o1))
console.log(ids.put(o1, o2, o3))