-
Notifications
You must be signed in to change notification settings - Fork 6
/
hamt.js.map
1 lines (1 loc) · 47.5 KB
/
hamt.js.map
1
{"version":3,"sources":["hamt.js"],"names":["hamt","SIZE","BUCKET_SIZE","Math","pow","MASK","MAX_INDEX_NODE","MIN_ARRAY_NODE","nothing","constant","x","hash","type","str","i","len","length","c","charCodeAt","popcount","hashFragment","shift","h","toBitmap","fromBitmap","bitmap","bit","arrayUpdate","mutate","at","v","arr","out","Array","arraySpliceOut","newLen","g","arraySpliceIn","LEAF","COLLISION","INDEX","ARRAY","empty","__hamt_isEmpty","isEmptyNode","Leaf","edit","key","value","_modify","Leaf__modify","Collision","children","Collision__modify","IndexedNode","mask","IndexedNode__modify","ArrayNode","size","ArrayNode__modify","isLeaf","node","expand","frag","child","subNodes","count","pack","removed","elements","elem","mergeLeaves","h1","n1","h2","n2","subH1","subH2","updateCollisionList","keyEq","list","f","k","newValue","canEditNode","canEdit","indx","exists","current","newChildren","newChild","Map","editable","config","root","_editable","_edit","_config","_root","_size","prototype","setTree","newRoot","newSize","tryGetHash","alt","map","tryGet","getHash","undefined","get","hasHash","has","defKeyCompare","y","make","isEmpty","modifyHash","NaN","modify","setHash","set","del","removeHash","deleteHash","remove","delete","beginMutation","endMutation","transient","appk","lazyVisitChildren","lazyVisit","rest","DONE","done","MapIterator","next","v0","Symbol","iterator","visit","buildPairs","entries","buildKeys","keys","buildValues","values","fold","z","m","toVisit","pop","push","forEach","_","Object","defineProperty","module","exports","define","amd"],"mappings":";;;;AAAA;;;;;AAKA,IAAMA,OAAO,EAAb,C,CAAiB;;AAEjB;;AAEA,IAAMC,OAAO,CAAb;;AAEA,IAAMC,cAAcC,KAAKC,GAAL,CAAS,CAAT,EAAYH,IAAZ,CAApB;;AAEA,IAAMI,OAAOH,cAAc,CAA3B;;AAEA,IAAMI,iBAAiBJ,cAAc,CAArC;;AAEA,IAAMK,iBAAiBL,cAAc,CAArC;;AAEA;;AAEA,IAAMM,UAAW,EAAjB;;AAEA,IAAM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AEA;AACH,cAAKA,IAAL,GAAYA,IAAZ;AACH","file":"hamt.js","sourcesContent":["/**\n @fileOverview Hash Array Mapped Trie.\n\n Code based on: https://github.com/exclipy/pdata\n*/\nconst hamt = {}; // export\n\n/* Configuration\n ******************************************************************************/\nconst SIZE = 5;\n\nconst BUCKET_SIZE = Math.pow(2, SIZE);\n\nconst MASK = BUCKET_SIZE - 1;\n\nconst MAX_INDEX_NODE = BUCKET_SIZE / 2;\n\nconst MIN_ARRAY_NODE = BUCKET_SIZE / 4;\n\n/*\n ******************************************************************************/\nconst nothing = ({});\n\nconst constant = x => () => x;\n\n/**\n Get 32 bit hash of string.\n\n Based on:\n http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery\n*/\nconst hash = hamt.hash = str => {\n const type = typeof str;\n if (type === 'number')\n return str;\n if (type !== 'string')\n str += '';\n\n let hash = 0;\n for (let i = 0, len = str.length; i < len; ++i) {\n const c = str.charCodeAt(i);\n hash = (((hash << 5) - hash) + c) | 0;\n }\n return hash;\n};\n\n/* Bit Ops\n ******************************************************************************/\n/**\n Hamming weight.\n\n Taken from: http://jsperf.com/hamming-weight\n*/\nconst popcount = (x) => {\n x -= ((x >> 1) & 0x55555555);\n x = (x & 0x33333333) + ((x >> 2) & 0x33333333);\n x = (x + (x >> 4)) & 0x0f0f0f0f;\n x += (x >> 8);\n x += (x >> 16);\n return (x & 0x7f);\n};\n\nconst hashFragment = (shift, h) =>\n (h >>> shift) & MASK;\n\nconst toBitmap = x =>\n 1 << x;\n\nconst fromBitmap = (bitmap, bit) =>\n popcount(bitmap & (bit - 1));\n\n/* Array Ops\n ******************************************************************************/\n/**\n Set a value in an array.\n\n @param mutate Should the input array be mutated?\n @param at Index to change.\n @param v New value\n @param arr Array.\n*/\nconst arrayUpdate = (mutate, at, v, arr) => {\n let out = arr;\n if (!mutate) {\n const len = arr.length;\n out = new Array(len);\n for (let i = 0; i < len; ++i)\n out[i] = arr[i];\n }\n out[at] = v;\n return out;\n};\n\n/**\n Remove a value from an array.\n\n @param mutate Should the input array be mutated?\n @param at Index to remove.\n @param arr Array.\n*/\nconst arraySpliceOut = (mutate, at, arr) => {\n const newLen = arr.length - 1;\n let i = 0;\n let g = 0;\n let out = arr;\n if (mutate) {\n i = g = at;\n } else {\n out = new Array(newLen);\n while (i < at)\n out[g++] = arr[i++];\n }\n ++i;\n while (i <= newLen)\n out[g++] = arr[i++];\n if (mutate) {\n out.length = newLen;\n }\n return out;\n};\n\n/**\n Insert a value into an array.\n\n @param mutate Should the input array be mutated?\n @param at Index to insert at.\n @param v Value to insert,\n @param arr Array.\n*/\nconst arraySpliceIn = (mutate, at, v, arr) => {\n const len = arr.length;\n if (mutate) {\n let i = len;\n while (i >= at)\n arr[i--] = arr[i];\n arr[at] = v;\n return arr;\n }\n let i = 0, g = 0;\n const out = new Array(len + 1);\n while (i < at)\n out[g++] = arr[i++];\n out[at] = v;\n while (i < len)\n out[++g] = arr[i++];\n return out;\n};\n\n/* Node Structures\n ******************************************************************************/\nconst LEAF = 1;\nconst COLLISION = 2;\nconst INDEX = 3;\nconst ARRAY = 4;\n\n/**\n Empty node.\n*/\nconst empty = ({\n __hamt_isEmpty: true\n});\n\nconst isEmptyNode = x =>\n x === empty || (x && x.__hamt_isEmpty);\n\n/**\n Leaf holding a value.\n\n @member edit Edit of the node.\n @member hash Hash of key.\n @member key Key.\n @member value Value stored.\n*/\nconst Leaf = (edit, hash, key, value) => ({\n type: LEAF,\n edit: edit,\n hash: hash,\n key: key,\n value: value,\n _modify: Leaf__modify\n});\n\n/**\n Leaf holding multiple values with the same hash but different keys.\n\n @member edit Edit of the node.\n @member hash Hash of key.\n @member children Array of collision children node.\n*/\nconst Collision = (edit, hash, children) => ({\n type: COLLISION,\n edit: edit,\n hash: hash,\n children: children,\n _modify: Collision__modify\n});\n\n/**\n Internal node with a sparse set of children.\n\n Uses a bitmap and array to pack children.\n\n @member edit Edit of the node.\n @member mask Bitmap that encode the positions of children in the array.\n @member children Array of child nodes.\n*/\nconst IndexedNode = (edit, mask, children) => ({\n type: INDEX,\n edit: edit,\n mask: mask,\n children: children,\n _modify: IndexedNode__modify\n});\n\n/**\n Internal node with many children.\n\n @member edit Edit of the node.\n @member size Number of children.\n @member children Array of child nodes.\n*/\nconst ArrayNode = (edit, size, children) => ({\n type: ARRAY,\n edit: edit,\n size: size,\n children: children,\n _modify: ArrayNode__modify\n});\n\n/**\n Is `node` a leaf node?\n*/\nconst isLeaf = node =>\n (node === empty || node.type === LEAF || node.type === COLLISION);\n\n/* Internal node operations.\n ******************************************************************************/\n/**\n Expand an indexed node into an array node.\n\n @param edit Current edit.\n @param frag Index of added child.\n @param child Added child.\n @param mask Index node mask before child added.\n @param subNodes Index node children before child added.\n*/\nconst expand = (edit, frag, child, bitmap, subNodes) => {\n const arr = [];\n let bit = bitmap;\n let count = 0;\n for (let i = 0; bit; ++i) {\n if (bit & 1)\n arr[i] = subNodes[count++];\n bit >>>= 1;\n }\n arr[frag] = child;\n return ArrayNode(edit, count + 1, arr);\n};\n\n/**\n Collapse an array node into a indexed node.\n\n @param edit Current edit.\n @param count Number of elements in new array.\n @param removed Index of removed element.\n @param elements Array node children before remove.\n*/\nconst pack = (edit, count, removed, elements) => {\n const children = new Array(count - 1);\n let g = 0;\n let bitmap = 0;\n for (let i = 0, len = elements.length; i < len; ++i) {\n if (i !== removed) {\n const elem = elements[i];\n if (elem && !isEmptyNode(elem)) {\n children[g++] = elem;\n bitmap |= 1 << i;\n }\n }\n }\n return IndexedNode(edit, bitmap, children);\n};\n\n/**\n Merge two leaf nodes.\n\n @param shift Current shift.\n @param h1 Node 1 hash.\n @param n1 Node 1.\n @param h2 Node 2 hash.\n @param n2 Node 2.\n*/\nconst mergeLeaves = (edit, shift, h1, n1, h2, n2) => {\n if (h1 === h2)\n return Collision(edit, h1, [n2, n1]);\n\n const subH1 = hashFragment(shift, h1);\n const subH2 = hashFragment(shift, h2);\n return IndexedNode(edit, toBitmap(subH1) | toBitmap(subH2),\n subH1 === subH2\n ? [mergeLeaves(edit, shift + SIZE, h1, n1, h2, n2)]\n : subH1 < subH2 ? [n1, n2] : [n2, n1]);\n};\n\n/**\n Update an entry in a collision list.\n\n @param mutate Should mutation be used?\n @param edit Current edit.\n @param keyEq Key compare function.\n @param hash Hash of collision.\n @param list Collision list.\n @param f Update function.\n @param k Key to update.\n @param size Size ref.\n*/\nconst updateCollisionList = (mutate, edit, keyEq, h, list, f, k, size) => {\n const len = list.length;\n for (let i = 0; i < len; ++i) {\n const child = list[i];\n if (keyEq(k, child.key)) {\n const value = child.value;\n const newValue = f(value);\n if (newValue === value)\n return list;\n\n if (newValue === nothing) {\n --size.value;\n return arraySpliceOut(mutate, i, list);\n }\n return arrayUpdate(mutate, i, Leaf(edit, h, k, newValue), list);\n }\n }\n\n const newValue = f();\n if (newValue === nothing)\n return list;\n ++size.value;\n return arrayUpdate(mutate, len, Leaf(edit, h, k, newValue), list);\n};\n\nconst canEditNode = (edit, node) => edit === node.edit;\n\n/* Editing\n ******************************************************************************/\nconst Leaf__modify = function (edit, keyEq, shift, f, h, k, size) {\n if (keyEq(k, this.key)) {\n const v = f(this.value);\n if (v === this.value)\n return this;\n else if (v === nothing) {\n --size.value;\n return empty;\n }\n if (canEditNode(edit, this)) {\n this.value = v;\n return this;\n }\n return Leaf(edit, h, k, v);\n }\n const v = f();\n if (v === nothing)\n return this;\n ++size.value;\n return mergeLeaves(edit, shift, this.hash, this, h, Leaf(edit, h, k, v));\n};\n\nconst Collision__modify = function (edit, keyEq, shift, f, h, k, size) {\n if (h === this.hash) {\n const canEdit = canEditNode(edit, this);\n const list = updateCollisionList(canEdit, edit, keyEq, this.hash, this.children, f, k, size);\n if (list === this.children)\n return this;\n\n return list.length > 1\n ? Collision(edit, this.hash, list)\n : list[0]; // collapse single element collision list\n }\n const v = f();\n if (v === nothing)\n return this;\n ++size.value;\n return mergeLeaves(edit, shift, this.hash, this, h, Leaf(edit, h, k, v));\n};\n\nconst IndexedNode__modify = function (edit, keyEq, shift, f, h, k, size) {\n const mask = this.mask;\n const children = this.children;\n const frag = hashFragment(shift, h);\n const bit = toBitmap(frag);\n const indx = fromBitmap(mask, bit);\n const exists = mask & bit;\n const current = exists ? children[indx] : empty;\n const child = current._modify(edit, keyEq, shift + SIZE, f, h, k, size);\n\n if (current === child)\n return this;\n\n const canEdit = canEditNode(edit, this);\n let bitmap = mask;\n let newChildren;\n if (exists && isEmptyNode(child)) { // remove\n bitmap &= ~bit;\n if (!bitmap)\n return empty;\n if (children.length <= 2 && isLeaf(children[indx ^ 1]))\n return children[indx ^ 1] // collapse\n\n newChildren = arraySpliceOut(canEdit, indx, children);\n } else if (!exists && !isEmptyNode(child)) { // add\n if (children.length >= MAX_INDEX_NODE)\n return expand(edit, frag, child, mask, children);\n\n bitmap |= bit;\n newChildren = arraySpliceIn(canEdit, indx, child, children);\n } else { // modify\n newChildren = arrayUpdate(canEdit, indx, child, children);\n }\n\n if (canEdit) {\n this.mask = bitmap;\n this.children = newChildren;\n return this;\n }\n return IndexedNode(edit, bitmap, newChildren);\n};\n\nconst ArrayNode__modify = function (edit, keyEq, shift, f, h, k, size) {\n let count = this.size;\n const children = this.children;\n const frag = hashFragment(shift, h);\n const child = children[frag];\n const newChild = (child || empty)._modify(edit, keyEq, shift + SIZE, f, h, k, size);\n\n if (child === newChild)\n return this;\n\n const canEdit = canEditNode(edit, this);\n let newChildren;\n if (isEmptyNode(child) && !isEmptyNode(newChild)) { // add\n ++count;\n newChildren = arrayUpdate(canEdit, frag, newChild, children);\n } else if (!isEmptyNode(child) && isEmptyNode(newChild)) { // remove\n --count;\n if (count <= MIN_ARRAY_NODE)\n return pack(edit, count, frag, children);\n newChildren = arrayUpdate(canEdit, frag, empty, children);\n } else { // modify\n newChildren = arrayUpdate(canEdit, frag, newChild, children);\n }\n\n if (canEdit) {\n this.size = count;\n this.children = newChildren;\n return this;\n }\n return ArrayNode(edit, count, newChildren);\n};\n\nempty._modify = (edit, keyEq, shift, f, h, k, size) => {\n const v = f();\n if (v === nothing)\n return empty;\n ++size.value;\n return Leaf(edit, h, k, v);\n};\n\n/*\n ******************************************************************************/\nfunction Map(editable, edit, config, root, size) {\n this._editable = editable;\n this._edit = edit;\n this._config = config;\n this._root = root;\n this._size = size;\n};\n\nMap.prototype.setTree = function (newRoot, newSize) {\n if (this._editable) {\n this._root = newRoot;\n this._size = newSize;\n return this;\n }\n return newRoot === this._root\n ? this\n : new Map(this._editable, this._edit, this._config, newRoot, newSize);\n};\n\n/* Queries\n ******************************************************************************/\n/**\n Lookup the value for `key` in `map` using a custom `hash`.\n\n Returns the value or `alt` if none.\n*/\nconst tryGetHash = hamt.tryGetHash = (alt, hash, key, map) => {\n let node = map._root;\n let shift = 0;\n const keyEq = map._config.keyEq;\n while (true) switch (node.type) {\n case LEAF:\n {\n return keyEq(key, node.key) ? node.value : alt;\n }\n case COLLISION:\n {\n if (hash === node.hash) {\n const children = node.children;\n for (let i = 0, len = children.length; i < len; ++i) {\n const child = children[i];\n if (keyEq(key, child.key))\n return child.value;\n }\n }\n return alt;\n }\n case INDEX:\n {\n const frag = hashFragment(shift, hash);\n const bit = toBitmap(frag);\n if (node.mask & bit) {\n node = node.children[fromBitmap(node.mask, bit)]\n shift += SIZE;\n break;\n }\n return alt;\n }\n case ARRAY:\n {\n node = node.children[hashFragment(shift, hash)];\n if (node) {\n shift += SIZE;\n break;\n }\n return alt;\n }\n default:\n return alt;\n }\n};\n\nMap.prototype.tryGetHash = function (alt, hash, key) {\n return tryGetHash(alt, hash, key, this);\n};\n\n/**\n Lookup the value for `key` in `map` using internal hash function.\n\n @see `tryGetHash`\n*/\nconst tryGet = hamt.tryGet = (alt, key, map) =>\n tryGetHash(alt, map._config.hash(key), key, map);\n\nMap.prototype.tryGet = function (alt, key) {\n return tryGet(alt, key, this);\n};\n\n/**\n Lookup the value for `key` in `map` using a custom `hash`.\n\n Returns the value or `undefined` if none.\n*/\nconst getHash = hamt.getHash = (hash, key, map) =>\n tryGetHash(undefined, hash, key, map);\n\nMap.prototype.getHash = function (hash, key) {\n return getHash(hash, key, this);\n};\n\n/**\n Lookup the value for `key` in `map` using internal hash function.\n\n @see `get`\n*/\nconst get = hamt.get = (key, map) =>\n tryGetHash(undefined, map._config.hash(key), key, map);\n\nMap.prototype.get = function (key, alt) {\n return tryGet(alt, key, this);\n};\n\n/**\n Does an entry exist for `key` in `map`? Uses custom `hash`.\n*/\nconst hasHash = hamt.has = (hash, key, map) =>\n tryGetHash(nothing, hash, key, map) !== nothing;\n\nMap.prototype.hasHash = function (hash, key) {\n return hasHash(hash, key, this);\n};\n\n/**\n Does an entry exist for `key` in `map`? Uses internal hash function.\n*/\nconst has = hamt.has = (key, map) =>\n hasHash(map._config.hash(key), key, map);\n\nMap.prototype.has = function (key) {\n return has(key, this);\n};\n\nconst defKeyCompare = (x, y) => x === y;\n\n/**\n Create an empty map.\n\n @param config Configuration.\n*/\nhamt.make = (config) =>\n new Map(0, 0, {\n keyEq: (config && config.keyEq) || defKeyCompare,\n hash: (config && config.hash) || hash\n }, empty, 0);\n\n/**\n Empty map.\n*/\nhamt.empty = hamt.make();\n\n/**\n Does `map` contain any elements?\n*/\nconst isEmpty = hamt.isEmpty = (map) =>\n map && !!isEmptyNode(map._root);\n\nMap.prototype.isEmpty = function () {\n return isEmpty(this);\n};\n\n/* Updates\n ******************************************************************************/\n/**\n Alter the value stored for `key` in `map` using function `f` using\n custom hash.\n\n `f` is invoked with the current value for `k` if it exists,\n or no arguments if no such value exists. `modify` will always either\n update or insert a value into the map.\n\n Returns a map with the modified value. Does not alter `map`.\n*/\nconst modifyHash = hamt.modifyHash = (f, hash, key, map) => {\n const size = { value: map._size };\n const newRoot = map._root._modify(\n map._editable ? map._edit : NaN,\n map._config.keyEq,\n 0,\n f,\n hash,\n key,\n size);\n return map.setTree(newRoot, size.value);\n};\n\nMap.prototype.modifyHash = function (hash, key, f) {\n return modifyHash(f, hash, key, this);\n};\n\n/**\n Alter the value stored for `key` in `map` using function `f` using\n internal hash function.\n\n @see `modifyHash`\n*/\nconst modify = hamt.modify = (f, key, map) =>\n modifyHash(f, map._config.hash(key), key, map);\n\nMap.prototype.modify = function (key, f) {\n return modify(f, key, this);\n};\n\n/**\n Store `value` for `key` in `map` using custom `hash`.\n\n Returns a map with the modified value. Does not alter `map`.\n*/\nconst setHash = hamt.setHash = (hash, key, value, map) =>\n modifyHash(constant(value), hash, key, map);\n\nMap.prototype.setHash = function (hash, key, value) {\n return setHash(hash, key, value, this);\n};\n\n/**\n Store `value` for `key` in `map` using internal hash function.\n\n @see `setHash`\n*/\nconst set = hamt.set = (key, value, map) =>\n setHash(map._config.hash(key), key, value, map);\n\nMap.prototype.set = function (key, value) {\n return set(key, value, this);\n};\n\n/**\n Remove the entry for `key` in `map`.\n\n Returns a map with the value removed. Does not alter `map`.\n*/\nconst del = constant(nothing);\nconst removeHash = hamt.removeHash = (hash, key, map) =>\n modifyHash(del, hash, key, map);\n\nMap.prototype.removeHash = Map.prototype.deleteHash = function (hash, key) {\n return removeHash(hash, key, this);\n};\n\n/**\n Remove the entry for `key` in `map` using internal hash function.\n\n @see `removeHash`\n*/\nconst remove = hamt.remove = (key, map) =>\n removeHash(map._config.hash(key), key, map);\n\nMap.prototype.remove = Map.prototype.delete = function (key) {\n return remove(key, this);\n};\n\n/* Mutation\n ******************************************************************************/\n/**\n Mark `map` as mutable.\n */\nconst beginMutation = hamt.beginMutation = (map) =>\n new Map(\n map._editable + 1,\n map._edit + 1,\n map._config,\n map._root,\n map._size);\n\nMap.prototype.beginMutation = function () {\n return beginMutation(this);\n};\n\n/**\n Mark `map` as immutable.\n */\nconst endMutation = hamt.endMutation = (map) => {\n map._editable = map._editable && map._editable - 1;\n return map;\n};\n\nMap.prototype.endMutation = function () {\n return endMutation(this);\n};\n\n/**\n Mutate `map` within the context of `f`.\n @param f\n @param map HAMT\n*/\nconst mutate = hamt.mutate = (f, map) => {\n const transient = beginMutation(map);\n f(transient);\n return endMutation(transient);\n};\n\nMap.prototype.mutate = function (f) {\n return mutate(f, this);\n};\n\n/* Traversal\n ******************************************************************************/\n/**\n Apply a continuation.\n*/\nconst appk = k =>\n k && lazyVisitChildren(k[0], k[1], k[2], k[3], k[4]);\n\n/**\n Recursively visit all values stored in an array of nodes lazily.\n*/\nvar lazyVisitChildren = (len, children, i, f, k) => {\n while (i < len) {\n const child = children[i++];\n if (child && !isEmptyNode(child))\n return lazyVisit(child, f, [len, children, i, f, k]);\n }\n return appk(k);\n};\n\n/**\n Recursively visit all values stored in `node` lazily.\n*/\nconst lazyVisit = (node, f, k) => {\n switch (node.type) {\n case LEAF:\n return {\n value: f(node),\n rest: k\n };\n\n case COLLISION:\n case ARRAY:\n case INDEX:\n const children = node.children;\n return lazyVisitChildren(children.length, children, 0, f, k);\n\n default:\n return appk(k);\n }\n};\n\nconst DONE = {\n done: true\n};\n\n/**\n Javascript iterator over a map.\n*/\nfunction MapIterator(v) {\n this.v = v;\n};\n\nMapIterator.prototype.next = function () {\n if (!this.v)\n return DONE;\n const v0 = this.v;\n this.v = appk(v0.rest);\n return v0;\n};\n\nMapIterator.prototype[Symbol.iterator] = function () {\n return this;\n};\n\n/**\n Lazily visit each value in map with function `f`.\n*/\nconst visit = (map, f) =>\n new MapIterator(lazyVisit(map._root, f));\n\n/**\n Get a Javascsript iterator of `map`.\n\n Iterates over `[key, value]` arrays.\n*/\nconst buildPairs = (x) => [x.key, x.value];\nconst entries = hamt.entries = (map) =>\n visit(map, buildPairs);\n\nMap.prototype.entries = Map.prototype[Symbol.iterator] = function () {\n return entries(this);\n};\n\n/**\n Get array of all keys in `map`.\n\n Order is not guaranteed.\n*/\nconst buildKeys = (x) => x.key;\nconst keys = hamt.keys = (map) =>\n visit(map, buildKeys);\n\nMap.prototype.keys = function () {\n return keys(this);\n}\n\n/**\n Get array of all values in `map`.\n\n Order is not guaranteed, duplicates are preserved.\n*/\nconst buildValues = x => x.value;\nconst values = hamt.values = Map.prototype.values = map =>\n visit(map, buildValues);\n\nMap.prototype.values = function () {\n return values(this);\n};\n\n/* Fold\n ******************************************************************************/\n/**\n Visit every entry in the map, aggregating data.\n\n Order of nodes is not guaranteed.\n\n @param f Function mapping accumulated value, value, and key to new value.\n @param z Starting value.\n @param m HAMT\n*/\nconst fold = hamt.fold = (f, z, m) => {\n const root = m._root;\n if (root.type === LEAF)\n return f(z, root.value, root.key);\n\n const toVisit = [root.children];\n let children;\n while (children = toVisit.pop()) {\n for (let i = 0, len = children.length; i < len;) {\n const child = children[i++];\n if (child && child.type) {\n if (child.type === LEAF)\n z = f(z, child.value, child.key);\n else\n toVisit.push(child.children);\n }\n }\n }\n return z;\n};\n\nMap.prototype.fold = function (f, z) {\n return fold(f, z, this);\n};\n\n/**\n Visit every entry in the map, aggregating data.\n\n Order of nodes is not guaranteed.\n\n @param f Function invoked with value and key\n @param map HAMT\n*/\nconst forEach = hamt.forEach = (f, map) =>\n fold((_, value, key) => f(value, key, map), null, map);\n\nMap.prototype.forEach = function (f) {\n return forEach(f, this);\n};\n\n/* Aggregate\n ******************************************************************************/\n/**\n Get the number of entries in `map`.\n*/\nconst count = hamt.count = map =>\n map._size;\n\nMap.prototype.count = function () {\n return count(this);\n};\n\nObject.defineProperty(Map.prototype, 'size', {\n get: Map.prototype.count\n});\n\n/* Export\n ******************************************************************************/\nif (typeof module !== 'undefined' && module.exports) {\n module.exports = hamt;\n} else if (typeof define === 'function' && define.amd) {\n define('hamt', [], () => hamt);\n} else {\n this.hamt = hamt;\n}\n"]}