the-forest/client/node_modules/.cache/babel-loader/0a9d3c9c8e80e3a510c11cc5c84e71008c240654cef19055022dcef284e0c2bb.json
2024-09-17 20:35:18 -04:00

1 line
5.6 KiB
JSON

{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.IdAlloc = void 0;\nconst errors_js_1 = require(\"./errors.js\");\n// An allocator of non-negative integer ids.\n//\n// This clever data structure has these \"ideal\" properties:\n// - It consumes memory proportional to the number of used ids (which is optimal).\n// - All operations are O(1) time.\n// - The allocated ids are small (with a slight modification, we could always provide the smallest possible\n// id).\nclass IdAlloc {\n // Set of all allocated ids\n #usedIds;\n // Set of all free ids lower than `#usedIds.size`\n #freeIds;\n constructor() {\n this.#usedIds = new Set();\n this.#freeIds = new Set();\n }\n // Returns an id that was free, and marks it as used.\n alloc() {\n // this \"loop\" is just a way to pick an arbitrary element from the `#freeIds` set\n for (const freeId of this.#freeIds) {\n this.#freeIds.delete(freeId);\n this.#usedIds.add(freeId);\n // maintain the invariant of `#freeIds`\n if (!this.#usedIds.has(this.#usedIds.size - 1)) {\n this.#freeIds.add(this.#usedIds.size - 1);\n }\n return freeId;\n }\n // the `#freeIds` set is empty, so there are no free ids lower than `#usedIds.size`\n // this means that `#usedIds` is a set that contains all numbers from 0 to `#usedIds.size - 1`,\n // so `#usedIds.size` is free\n const freeId = this.#usedIds.size;\n this.#usedIds.add(freeId);\n return freeId;\n }\n free(id) {\n if (!this.#usedIds.delete(id)) {\n throw new errors_js_1.InternalError(\"Freeing an id that is not allocated\");\n }\n // maintain the invariant of `#freeIds`\n this.#freeIds.delete(this.#usedIds.size);\n if (id < this.#usedIds.size) {\n this.#freeIds.add(id);\n }\n }\n}\nexports.IdAlloc = IdAlloc;","map":{"version":3,"names":["Object","defineProperty","exports","value","IdAlloc","errors_js_1","require","usedIds","freeIds","constructor","Set","alloc","freeId","delete","add","has","size","free","id","InternalError"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-cjs/id_alloc.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.IdAlloc = void 0;\nconst errors_js_1 = require(\"./errors.js\");\n// An allocator of non-negative integer ids.\n//\n// This clever data structure has these \"ideal\" properties:\n// - It consumes memory proportional to the number of used ids (which is optimal).\n// - All operations are O(1) time.\n// - The allocated ids are small (with a slight modification, we could always provide the smallest possible\n// id).\nclass IdAlloc {\n // Set of all allocated ids\n #usedIds;\n // Set of all free ids lower than `#usedIds.size`\n #freeIds;\n constructor() {\n this.#usedIds = new Set();\n this.#freeIds = new Set();\n }\n // Returns an id that was free, and marks it as used.\n alloc() {\n // this \"loop\" is just a way to pick an arbitrary element from the `#freeIds` set\n for (const freeId of this.#freeIds) {\n this.#freeIds.delete(freeId);\n this.#usedIds.add(freeId);\n // maintain the invariant of `#freeIds`\n if (!this.#usedIds.has(this.#usedIds.size - 1)) {\n this.#freeIds.add(this.#usedIds.size - 1);\n }\n return freeId;\n }\n // the `#freeIds` set is empty, so there are no free ids lower than `#usedIds.size`\n // this means that `#usedIds` is a set that contains all numbers from 0 to `#usedIds.size - 1`,\n // so `#usedIds.size` is free\n const freeId = this.#usedIds.size;\n this.#usedIds.add(freeId);\n return freeId;\n }\n free(id) {\n if (!this.#usedIds.delete(id)) {\n throw new errors_js_1.InternalError(\"Freeing an id that is not allocated\");\n }\n // maintain the invariant of `#freeIds`\n this.#freeIds.delete(this.#usedIds.size);\n if (id < this.#usedIds.size) {\n this.#freeIds.add(id);\n }\n }\n}\nexports.IdAlloc = IdAlloc;\n"],"mappings":"AAAA,YAAY;;AACZA,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,OAAO,GAAG,KAAK,CAAC;AACxB,MAAMC,WAAW,GAAGC,OAAO,CAAC,aAAa,CAAC;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,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