{"version":3,"file":"c_array-keyed-map_c49e5297.1710586201733.js","sources":["../../node_modules/array-keyed-map/main.js"],"sourcesContent":["/*\n # Implementation strategy\n\n Create a tree of `Map`s, such that indexing the tree recursively (with items\n of a key array, sequentially), traverses the tree, so that when the key array\n is exhausted, the tree node we arrive at contains the value for that key\n array under the guaranteed-unique `Symbol` key `dataSymbol`.\n\n ## Example\n\n Start with an empty `ArrayKeyedMap` tree:\n\n {\n }\n\n Add ['a'] → 1:\n\n {\n 'a': {\n [dataSymbol]: 1,\n },\n }\n\n Add [] → 0:\n\n {\n [dataSymbol]: 0,\n 'a': {\n [dataSymbol]: 1,\n },\n }\n\n Add ['a', 'b', 'c', 'd'] → 4:\n\n {\n [dataSymbol]: 0,\n 'a': {\n [dataSymbol]: 1,\n 'b': {\n 'c': {\n 'd': {\n [dataSymbol]: 4,\n },\n },\n },\n },\n }\n\n String array keys are used in the above example for simplicity. In reality,\n we can support any values in array keys, because `Map`s do.\n*/\n\nconst dataSymbol = Symbol('path-store-trunk')\n\n//\n// This class represents the external API\n//\n\nclass ArrayKeyedMap {\n constructor (initialEntries = []) {\n this._root = new Map()\n this._size = 0\n for (const [k, v] of initialEntries) { this.set(k, v) }\n }\n\n set (path, value) { return set.call(this, path, value) }\n\n has (path) { return has.call(this, path) }\n\n get (path) { return get.call(this, path) }\n\n delete (path) { return del.call(this, path) }\n\n get size () { return this._size }\n\n clear () {\n this._root.clear()\n this._size = 0\n }\n\n hasPrefix (path) { return hasPrefix.call(this, path) }\n\n get [Symbol.toStringTag] () { return 'ArrayKeyedMap' }\n\n * [Symbol.iterator] () { yield * entries.call(this) }\n\n * entries () { yield * entries.call(this) }\n\n * keys () { yield * keys.call(this) }\n\n * values () { yield * values.call(this) }\n\n forEach (callback, thisArg) { forEach.call(this, callback, thisArg) }\n}\n\nmodule.exports = ArrayKeyedMap\n\n//\n// These stateless functions implement the internals\n//\n\nfunction set (path, value) {\n let map = this._root\n for (const item of path) {\n let nextMap = map.get(item)\n if (!nextMap) {\n // Create next map if none exists\n nextMap = new Map()\n map.set(item, nextMap)\n }\n map = nextMap\n }\n\n // Reached end of path. Set the data symbol to the given value, and\n // increment size if nothing was here before.\n if (!map.has(dataSymbol)) this._size += 1\n map.set(dataSymbol, value)\n return this\n}\n\nfunction has (path) {\n let map = this._root\n for (const item of path) {\n const nextMap = map.get(item)\n if (nextMap) {\n map = nextMap\n } else {\n return false\n }\n }\n return map.has(dataSymbol)\n}\n\nfunction get (path) {\n let map = this._root\n for (const item of path) {\n map = map.get(item)\n if (!map) return undefined\n }\n return map.get(dataSymbol)\n}\n\nfunction del (path) {\n let map = this._root\n\n // Maintain a stack of maps we visited, so we can go back and trim empty ones\n // if we delete something.\n const stack = []\n\n for (const item of path) {\n const nextMap = map.get(item)\n if (nextMap) {\n stack.unshift({ parent: map, child: nextMap, item })\n map = nextMap\n } else {\n // Nothing to delete\n return false\n }\n }\n\n // Reached end of path. Delete data, if it exists.\n const hadPreviousValue = map.delete(dataSymbol)\n\n // If something was deleted, decrement size and go through the stack of\n // visited maps, trimming any that are now empty.\n if (hadPreviousValue) {\n this._size -= 1\n\n for (const { parent, child, item } of stack) {\n if (child.size === 0) {\n parent.delete(item)\n }\n }\n }\n return hadPreviousValue\n}\n\nfunction hasPrefix (path) {\n let map = this._root\n for (const item of path) {\n map = map.get(item)\n if (!map) return false\n }\n return true\n}\n\nfunction * entries () {\n const stack = [{ path: [], map: this._root }]\n while (stack.length > 0) {\n const { path, map } = stack.pop()\n for (const [k, v] of map.entries()) {\n if (k === dataSymbol) yield [path, v]\n else stack.push({ path: path.concat([k]), map: v })\n }\n }\n}\n\nfunction * keys () {\n for (const [k] of this.entries()) yield k\n}\n\nfunction * values () {\n for (const [, v] of this.entries()) yield v\n}\n\nfunction forEach (callback, thisArg) {\n for (const [k, v] of this.entries()) callback.call(thisArg, v, k, this)\n}\n"],"names":["dataSymbol","ArrayKeyedMap","initialEntries","k","v","path","value","set","has","get","del","hasPrefix","entries","keys","values","callback","thisAr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