UNPKG

the-world-engine

Version:

three.js based, unity like game engine for browser

61 lines (60 loc) 1.52 kB
import { OrderedSet } from "js-sdsl"; export class MutIteratableCollection { rt=null; nt; dt; ft; ut; constructor(t) { this.nt = new OrderedSet(undefined, t); this.dt = new OrderedSet(undefined, t); this.ft = new OrderedSet(undefined, t); this.ut = new OrderedSet(undefined, t); } get size() { return this.nt.size(); } insert(t) { t.isRemoved = false; if (this.rt !== null) { this.dt.insert(t); this.ut.eraseElementByKey(t); } else this.nt.insert(t); } delete(t) { if (this.rt !== null) { t.isRemoved = true; this.dt.eraseElementByKey(t); this.ut.insert(t); } else this.nt.eraseElementByKey(t); } clear() { this.nt.clear(); this.dt.clear(); this.ut.clear(); } forEach(t) { this.rt = this.nt; this.rt.forEach((e => { if (!e.isRemoved) t(e); })); do { this.rt = this._t(); this.rt.forEach((e => { if (!e.isRemoved) t(e); })); } while (0 < this.dt.size() || 0 < this.ut.size()); this.rt = null; } _t() { this.rt = null; this.ut.forEach((t => this.delete(t))); this.dt.forEach((t => this.insert(t))); const t = this.dt; this.dt = this.ft; this.ft = t; this.dt.clear(); this.ut.clear(); return t; } }