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AAI,EAAM,KAAK,aAAa,GAG5B,OAFI,GAAO,KAAK,WAAW,SACvB,EAAM,GACH,KAAK,KAAK,IAAI,KAAK,WAAW,GACzC,CACA,IAAA,CAAK,EAAK,GAEN,GADA,KAAK,mBAAmB,EAAK,OACN,IAAnB,KAAK,KAAK,MAAc,GAAS,EACjC,MAAO,GACX,MAAM,EAAS,GACT,EAAO,IAAI,IACX,EAAW,OAAO,GACxB,IAAI,EAAM,KAAK,aAAa,GAC5B,IAAK,IAAI,EAAI,EAAG,EAAI,KAAK,WAAW,QAAU,EAAO,OAAS,EAAO,IAAK,CAClE,GAAO,KAAK,WAAW,SACvB,EAAM,GACV,MAAM,EAAO,KAAK,KAAK,IAAI,KAAK,WAAW,IACvC,IAAS,EAAK,IAAI,KAClB,EAAK,IAAI,GACT,EAAO,KAAK,IAEhB,GACJ,CACA,OAAO,CACX,CACA,QAAI,GACA,OAAO,KAAK,iBAAiB,IACjC,CACA,SAAI,GACA,OAAO,MAAM,KAAK,KAAK,iBAC3B,CACA,MAAA,GACI,MAAO,CACH,MAAO,KAAK,MACZ,SAAU,KAAK,SAEvB,CACA,eAAO,CAAS,GACZ,MAAM,EAAO,IAAI,UAAU,CAAE,SAAU,EAAK,WAC5C,IAAK,MAAM,KAAQ,EAAK,MACpB,EAAK,IAAI,GAEb,OAAO,CACX,CACA,QAAA,GACI,MAAO,mBAAmB,KAAK,mBAAmB,KAAK,WAAW,oBAAoB,KAAK,WAC/F","file":"/npm/hash-orbit@1.0.1/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/hash-orbit@1.0.1/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { hash32 } from 'murmur-hash';\nexport { hash32 };\nexport class HashOrbit {\n    constructor(options = {}) {\n        this.replicas = options.replicas ?? 150;\n        this.ring = new Map();\n        this.sortedKeys = [];\n    }\n    validateIdentifier(value, name) {\n        if (!value) {\n            throw new Error(`${name} cannot be empty`);\n        }\n        if (value.length > 1000) {\n            throw new Error(`${name} exceeds maximum length of 1000 characters`);\n        }\n    }\n    getUniqueNodes() {\n        return new Set(this.ring.values());\n    }\n    add(node) {\n        this.validateIdentifier(node, 'Node identifier');\n        for (let i = 0; i < this.replicas; i++) {\n            const key = `${node}:${i}`;\n            const position = hash32(key);\n            this.ring.set(position, node);\n        }\n        this.sortedKeys = [...this.ring.keys()].sort((a, b) => a - b);\n    }\n    remove(node) {\n        this.validateIdentifier(node, 'Node identifier');\n        for (let i = 0; i < this.replicas; i++) {\n            const key = `${node}:${i}`;\n            const position = hash32(key);\n            this.ring.delete(position);\n        }\n        this.sortedKeys = [...this.ring.keys()].sort((a, b) => a - b);\n    }\n    binarySearch(target) {\n        let left = 0;\n        let right = this.sortedKeys.length;\n        while (left < right) {\n            const mid = Math.floor((left + right) / 2);\n            if (this.sortedKeys[mid] < target) {\n                left = mid + 1;\n            }\n            else {\n                right = mid;\n            }\n        }\n        return left;\n    }\n    get(key) {\n        this.validateIdentifier(key, 'Key');\n        if (this.ring.size === 0)\n            return undefined;\n        const position = hash32(key);\n        let idx = this.binarySearch(position);\n        if (idx >= this.sortedKeys.length)\n            idx = 0;\n        return this.ring.get(this.sortedKeys[idx]);\n    }\n    getN(key, count) {\n        this.validateIdentifier(key, 'Key');\n        if (this.ring.size === 0 || count <= 0)\n            return [];\n        const result = [];\n        const seen = new Set();\n        const position = hash32(key);\n        let idx = this.binarySearch(position);\n        for (let i = 0; i < this.sortedKeys.length && result.length < count; i++) {\n            if (idx >= this.sortedKeys.length)\n                idx = 0;\n            const node = this.ring.get(this.sortedKeys[idx]);\n            if (node && !seen.has(node)) {\n                seen.add(node);\n                result.push(node);\n            }\n            idx++;\n        }\n        return result;\n    }\n    get size() {\n        return this.getUniqueNodes().size;\n    }\n    get nodes() {\n        return Array.from(this.getUniqueNodes());\n    }\n    toJSON() {\n        return {\n            nodes: this.nodes,\n            replicas: this.replicas,\n        };\n    }\n    static fromJSON(json) {\n        const ring = new HashOrbit({ replicas: json.replicas });\n        for (const node of json.nodes) {\n            ring.add(node);\n        }\n        return ring;\n    }\n    toString() {\n        return `HashOrbit(nodes=${this.size}, positions=${this.sortedKeys.length}, replicas=${this.replicas})`;\n    }\n}\n"]}