atsds-egg 0.0.12-alpha2 → 0.0.13-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -1
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{List as t}from"atsds";class s extends Map{factory;constructor(t){super(),this.factory=t}get(t){return this.has(t)||this.set(t,this.factory()),super.get(t)}}class e{parent;constructor(){this.parent=new Map}find(t){return this.parent.has(t)||this.parent.set(t,t),this.parent.get(t)!==t&&this.parent.set(t,this.find(this.parent.get(t))),this.parent.get(t)}union(t,s){const e=this.find(t),n=this.find(s);return e!==n&&this.parent.set(n,e),e}}class n{op;children;constructor(t,s){this.op=t,this.children=s}canonicalize(t){return new n(this.op,this.children.map(s=>t(s)))}key(){return`${this.op}(${this.children.join(",")})`}}class i{next_id=0;hashcons=new Map;unionfind=new e;classes=new s(()=>new Set);parents=new s(()=>new Set);worklist=new Set;freshId(){const t=this.next_id;return this.next_id+=1,t}find(t){return this.unionfind.find(t)}add(t){const s=this.termToEnode(t);return this.addEnode(s)}termToEnode(s){const e=s.term();if(e instanceof t){const t=[];for(let s=0;s<e.length();s++){const n=e.getitem(s),i=this.add(n);t.push(i)}return new n("()",t)}return new n(s.toString(),[])}addEnode(t){const s=(t=t.canonicalize(this.find.bind(this))).key(),e=this.hashcons.get(s);if(e)return this.find(e[1]);const n=this.freshId();this.hashcons.set(s,[t,n]),this.unionfind.parent.set(n,n),this.classes.get(n).add(t);for(const s of t.children)this.parents.get(s).add([t,n]);return n}merge(t,s){const e=this.find(t),n=this.find(s);if(e===n)return e;const i=this.unionfind.union(e,n);for(const t of this.classes.get(n))this.classes.get(i).add(t);this.classes.delete(n);for(const t of this.parents.get(n))this.parents.get(i).add(t);return this.parents.delete(n),this.worklist.add(i),i}rebuild(){for(;this.worklist.size>0;){const t=new Set(Array.from(this.worklist).map(t=>this.find(t)));this.worklist.clear();for(const s of t)this.repair(s)}}repair(t){const s=new Map;for(const[e,n]of this.parents.get(t)){this.hashcons.delete(e.key());const t=e.canonicalize(this.find.bind(this)),i=t.key(),r=this.find(n);s.has(i)?this.merge(r,s.get(i)[1]):(s.set(i,[t,r]),this.hashcons.set(i,[t,r]))}this.parents.get(t).clear();for(const[e,n]of s)this.parents.get(t).add(n)}}export{s as DefaultMap,i as EGraph,n as ENode,e as UnionFind};
1
+ class t extends Map{factory;constructor(t){super(),this.factory=t}get(t){return this.has(t)||this.set(t,this.factory()),super.get(t)}}class s{parent;constructor(){this.parent=new Map}find(t){return this.parent.has(t)||this.parent.set(t,t),this.parent.get(t)!==t&&this.parent.set(t,this.find(this.parent.get(t))),this.parent.get(t)}union(t,s){const e=this.find(t),n=this.find(s);return e!==n&&this.parent.set(n,e),e}}class e{op;children;constructor(t,s){this.op=t,this.children=s}canonicalize(t){return new e(this.op,this.children.map(s=>t(s)))}key(){return`${this.op}(${this.children.join(",")})`}}class n{next_id=0;hashcons=new Map;unionfind=new s;classes=new t(()=>new Set);parents=new t(()=>new Set);worklist=new Set;freshId(){const t=this.next_id;return this.next_id+=1,t}find(t){return this.unionfind.find(t)}add(t){const s=this.termToEnode(t);return this.addEnode(s)}termToEnode(t){const s=t.term();if("object"==typeof(n=s)&&null!==n&&"function"==typeof n.length&&"function"==typeof n.getitem){const t=[];for(let e=0;e<s.length();e++){const n=s.getitem(e),i=this.add(n);t.push(i)}return new e("()",t)}return new e(t.toString(),[]);var n}addEnode(t){const s=(t=t.canonicalize(this.find.bind(this))).key(),e=this.hashcons.get(s);if(e)return this.find(e[1]);const n=this.freshId();this.hashcons.set(s,[t,n]),this.unionfind.parent.set(n,n),this.classes.get(n).add(t);for(const s of t.children)this.parents.get(s).add([t,n]);return n}merge(t,s){const e=this.find(t),n=this.find(s);if(e===n)return e;const i=this.unionfind.union(e,n);for(const t of this.classes.get(n))this.classes.get(i).add(t);this.classes.delete(n);for(const t of this.parents.get(n))this.parents.get(i).add(t);return this.parents.delete(n),this.worklist.add(i),i}rebuild(){for(;this.worklist.size>0;){const t=new Set(Array.from(this.worklist).map(t=>this.find(t)));this.worklist.clear();for(const s of t)this.repair(s)}}repair(t){const s=new Map;for(const[e,n]of this.parents.get(t)){this.hashcons.delete(e.key());const t=e.canonicalize(this.find.bind(this)),i=t.key(),r=this.find(n);s.has(i)?this.merge(r,s.get(i)[1]):(s.set(i,[t,r]),this.hashcons.set(i,[t,r]))}this.parents.get(t).clear();for(const[e,n]of s)this.parents.get(t).add(n)}}export{t as DefaultMap,n as EGraph,e as ENode,s as UnionFind};
package/package.json CHANGED
@@ -24,7 +24,7 @@
24
24
  "all": "run-s build test"
25
25
  },
26
26
  "dependencies": {
27
- "atsds": "^0.0.11"
27
+ "atsds": "*"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@rollup/plugin-terser": "^0.4.4",
@@ -39,5 +39,5 @@
39
39
  "tslib": "^2.8.1",
40
40
  "typescript": "^5.9.3"
41
41
  },
42
- "version": "0.0.12-alpha2"
42
+ "version": "0.0.13-alpha1"
43
43
  }