weak-index

weakly assign ids to tuples of objects

Usage no npm install needed!

<script type="module">
  import weakIndex from 'https://cdn.skypack.dev/weak-index';
</script>

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))