UNPKG

low-level

Version:
109 lines 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UintSet = exports.BasicBinarySet = void 0; const uint_js_1 = require("./uint.js"); const utils_js_1 = require("./utils.js"); class BSetEntriesIterator extends utils_js_1.AbstractIterator { CLS; constructor(CLS, setEntries) { super(setEntries); this.CLS = CLS; } _next(value) { const decodedKey = this.CLS.from(value[0], "hex"); return [decodedKey, decodedKey]; } } class BSetIterator extends utils_js_1.AbstractIterator { CLS; constructor(CLS, setEntries) { super(setEntries); this.CLS = CLS; } _next(value) { return this.CLS.from(value, "hex"); } } class BasicBinarySet { CLS; store = new Set(); constructor(CLS, values) { this.CLS = CLS; if (values) { for (const value of values) { this.add(value); } } } get size() { return this.store.size; } add(value) { this.store.add(value.toHex()); return value; } delete(value) { return this.store.delete(value.toHex()); } has(value) { return this.store.has(value.toHex()); } [Symbol.iterator]() { return this.values(); } entries() { return new BSetEntriesIterator(this.CLS, this.store.entries()); } keys() { return this.values(); } values() { return new BSetIterator(this.CLS, this.store.values()); } forEach(callbackfn, thisArg) { for (const value of this.values()) { callbackfn.call(thisArg, value); } ; } /* public union<U>(other: ReadonlySetLike<U>): Set<K | U> { throw new Error("Method not implemented."); } public intersection<U>(other: ReadonlySetLike<U>): Set<K & U> { throw new Error("Method not implemented."); } public difference<U>(other: ReadonlySetLike<U>): Set<K> { throw new Error("Method not implemented."); } public symmetricDifference<U>(other: ReadonlySetLike<U>): Set<K | U> { throw new Error("Method not implemented."); } public isSubsetOf(other: ReadonlySetLike<unknown>): boolean { throw new Error("Method not implemented."); } public isSupersetOf(other: ReadonlySetLike<unknown>): boolean { throw new Error("Method not implemented."); } public isDisjointFrom(other: ReadonlySetLike<unknown>): boolean { throw new Error("Method not implemented."); } */ clear() { throw new Error("Method not implemented."); } getStringTag() { return this.constructor.name; } get [Symbol.toStringTag]() { return this.getStringTag(); } } exports.BasicBinarySet = BasicBinarySet; class UintSet extends BasicBinarySet { constructor(values) { super(uint_js_1.Uint, values); } } exports.UintSet = UintSet; //# sourceMappingURL=set.js.map