graph-builder
Version:
A graph builder library for modeling abstract graph structures.
77 lines • 2.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Iterators_1 = require("./Iterators");
class ImmutableSet extends Set {
constructor(values, readOperations) {
super(values);
this.initialized = false;
this.readOperations = readOperations || {
[Symbol.iterator]: () => super[Symbol.iterator](),
size: () => super.size,
has: (a) => super.has(a)
};
this.initialized = true;
}
static fromIterable(iterator) {
return new ImmutableSet(Array.from(iterator));
}
static fromSetOperations(operations) {
return new ImmutableSet(null, operations);
}
static of(node) {
return new ImmutableSet([node]);
}
static empty() {
return new ImmutableSet();
}
add(value) {
if (this.initialized) { // add is called in super's constructor
throw new Error('Not implemented');
}
return super.add(value);
}
clear() {
throw new Error('Not implemented');
}
delete(value) {
throw new Error('Not implemented');
}
forEach(callbackfn, thisArg) {
const iterator = this[Symbol.iterator]();
for (let value of iterator) {
callbackfn.call(thisArg || undefined, value, value, this);
}
}
has(value) {
return this.readOperations.has(value);
}
get size() {
return this.readOperations.size();
}
[Symbol.iterator]() {
const iterator = this.readOperations[Symbol.iterator]();
const iterableIterator = {
next: () => iterator.next(),
};
iterableIterator[Symbol.iterator] = () => iterableIterator;
return iterableIterator;
}
entries() {
const iterator = Iterators_1.Iterators.transform(this.readOperations[Symbol.iterator](), (a) => [a, a]);
const iterableIterator = {
next: () => iterator.next(),
[Symbol.iterator]: () => iterableIterator
};
return iterableIterator;
}
values() {
const iterator = this.readOperations[Symbol.iterator]();
const iterableIterator = {
next: () => iterator.next(),
[Symbol.iterator]: () => iterableIterator
};
return iterableIterator;
}
}
exports.ImmutableSet = ImmutableSet;
//# sourceMappingURL=ImmutableSet.js.map