low-level
Version:
81 lines • 1.9 kB
JavaScript
import { Uint } from "./uint.js";
import { AbstractIterator } from "./utils.js";
class BSetEntriesIterator extends 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 AbstractIterator {
CLS;
constructor(CLS, setEntries) {
super(setEntries);
this.CLS = CLS;
}
_next(value) {
return this.CLS.from(value, "hex");
}
}
export 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);
}
;
}
clear() {
throw new Error("Method not implemented.");
}
getStringTag() {
return this.constructor.name;
}
get [Symbol.toStringTag]() {
return this.getStringTag();
}
}
export class UintSet extends BasicBinarySet {
constructor(values) {
super(Uint, values);
}
}
//# sourceMappingURL=set.js.map