aboutsummaryrefslogtreecommitdiff
path: root/node_modules/concordance/lib/Registry.js
blob: f4a4b68085f2828ab88d63779a2d7d5f9b78ebd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict'

class Registry {
  constructor () {
    this.counter = 0
    this.map = new WeakMap()
  }

  has (value) {
    return this.map.has(value)
  }

  get (value) {
    return this.map.get(value).descriptor
  }

  alloc (value) {
    const index = ++this.counter
    const pointer = {descriptor: null, index}
    this.map.set(value, pointer)
    return pointer
  }
}
module.exports = Registry