UNPKG

@btc-vision/transaction

Version:

OPNet transaction library allows you to create and sign transactions for the OPNet network.

47 lines (46 loc) 1.14 kB
export class DeterministicSet { constructor(compareFn) { this.compareFn = compareFn; this.elements = []; } add(value) { if (!this.elements.includes(value)) { this.elements.push(value); this.elements.sort(this.compareFn); } } delete(value) { const index = this.elements.indexOf(value); if (index === -1) { return false; } this.elements.splice(index, 1); return true; } has(value) { return this.elements.includes(value); } clear() { this.elements = []; } forEach(callback) { for (const value of this.elements) { callback(value, this); } } static fromSet(set, compareFn) { const deterministicSet = new DeterministicSet(compareFn); for (const value of set) { deterministicSet.add(value); } return deterministicSet; } get size() { return this.elements.length; } *[Symbol.iterator]() { for (const value of this.elements) { yield value; } } }