@calcit/ternary-tree 0.0.18 → 0.0.19-a1
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.
- package/lib/{hash.d.ts → hash.d.mts} +0 -0
- package/lib/{hash.js → hash.mjs} +0 -0
- package/lib/index.d.mts +4 -0
- package/lib/index.mjs +4 -0
- package/lib/{list.d.ts → list.d.mts} +1 -1
- package/lib/{list.js → list.mjs} +3 -3
- package/lib/main.d.mts +2 -0
- package/lib/{main.js → main.mjs} +6 -6
- package/lib/{map.d.ts → map.d.mts} +1 -1
- package/lib/{map.js → map.mjs} +2 -2
- package/lib/{test-list.d.ts → test-list.d.mts} +0 -0
- package/lib/{test-list.js → test-list.mjs} +18 -2
- package/lib/{test-map.d.ts → test-map.d.mts} +0 -0
- package/lib/{test-map.js → test-map.mjs} +3 -3
- package/lib/{types.d.ts → types.d.mts} +0 -0
- package/lib/{types.js → types.mjs} +0 -0
- package/lib/{utils.d.ts → utils.d.mts} +1 -1
- package/lib/{utils.js → utils.mjs} +2 -2
- package/package.json +9 -7
- package/assets/index.html +0 -2
- package/lib/bundle.js +0 -3022
- package/lib/bundle.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -4
- package/lib/main.d.ts +0 -2
- package/src/costs.nim +0 -62
- package/src/hash.ts +0 -78
- package/src/index.ts +0 -5
- package/src/list.ts +0 -996
- package/src/main.ts +0 -20
- package/src/map.ts +0 -1341
- package/src/shape.nim +0 -62
- package/src/test-list.ts +0 -271
- package/src/test-map.ts +0 -288
- package/src/types.ts +0 -87
- package/src/utils.ts +0 -124
package/lib/bundle.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"bundle.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA0C;AAC2B;AACrE;AACO;AACP;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,eAAe;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA,qBAAqB,MAAM,qEAAiC;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,0DAAkB;AAC5C;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA,sBAAsB,YAAY;AAClC;AACA,oBAAoB,MAAM,mEAA+B;AACzD;AACA;AACA;AACA;AACO;AACP;AACA,yBAAyB,UAAU;AACnC;AACA,oBAAoB,MAAM,mEAA+B;AACzD;AACA;AACA;AACO;AACP,aAAa,MAAM,qEAAiC;AACpD;AACO;AACP,8BAA8B,UAAU;AACxC;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB,mEAA+B;AACxD;AACA;AACA,yBAAyB,qEAAiC;AAC1D;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C,sBAAsB,WAAW;AACjC,aAAa,qEAAiC;AAC9C;AACA,2HAA2H,YAAY,MAAM,qBAAqB,uBAAuB,oBAAoB;AAC7M;AACA;AACO;AACP;AACA;AACA,iBAAiB,mEAA+B;AAChD;AACA;AACA;AACA,iBAAiB,qEAAiC;AAClD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C,gBAAgB,iDAAS;AACzB;AACA;AACA;AACA;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,mEAA+B;AAChD;AACA;AACA;AACA;AACA,iBAAiB,qEAAiC;AAClD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACO;AACP,sBAAsB,qBAAqB;AAC3C;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,mEAA+B;AACzD;AACA;AACA;AACA;AACA,mEAAmE,IAAI;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qCAAqC,IAAI;AACzC;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,mEAA+B;AACrD;AACA,qBAAqB,MAAM,mEAA+B;AAC1D;AACA;AACA,+DAA+D,IAAI;AACnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,6CAA6C,IAAI;AACjD;AACA;AACA;AACA;AACA;AACA,2CAA2C,IAAI;AAC/C;AACA;AACA;AACA;AACA,sBAAsB,mEAA+B;AACrD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,mEAA+B;AACrD;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA,0BAA0B,MAAM,mEAA+B,wBAAwB;AACvF;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA,wBAAwB,MAAM,mEAA+B,wBAAwB;AACrF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA,0BAA0B,MAAM,mEAA+B,wBAAwB;AACvF;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA,wBAAwB,MAAM,mEAA+B,wBAAwB;AACrF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA;AACA,8BAA8B,MAAM,mEAA+B,wBAAwB;AAC3F;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA;AACA;AACA,6BAA6B,MAAM,mEAA+B,wBAAwB;AAC1F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA,4BAA4B,MAAM,mEAA+B,wBAAwB;AACzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA;AACA,8BAA8B,MAAM,mEAA+B,wBAAwB;AAC3F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA,wBAAwB,MAAM,mEAA+B,wBAAwB;AACrF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA,0BAA0B,MAAM,mEAA+B,wBAAwB;AACvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA,qBAAqB,MAAM,mEAA+B,wBAAwB;AAClF;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA,oBAAoB,MAAM,mEAA+B,wBAAwB;AACjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACO;AACP;AACA;AACA;AACO;AACP,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,mDAAW;AACvB;AACA;AACA;AACA;AACO;AACP;AACA,iBAAiB,MAAM,mEAA+B;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA,iBAAiB,MAAM,mEAA+B;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,mEAA+B,gBAAgB,mEAA+B;AAClG,aAAa,iDAAS;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,qEAAiC,gBAAgB,qEAAiC;AACtG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,mBAAmB;AACzC,aAAa,iDAAS;AACtB;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA,iBAAiB,mEAA+B;AAChD;AACA,wDAAwD,uBAAuB;AAC/E;AACA;AACA,iBAAiB,qEAAiC;AAClD;AACA,0DAA0D,uBAAuB;AACjF;AACA;AACA;AACA,2DAA2D,uBAAuB;AAClF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP,oBAAoB,sBAAsB,GAAG,SAAS,GAAG,OAAO;AAChE;AACA,gDAAgD,QAAQ,KAAK,KAAK;AAClE;AACA;AACA,gDAAgD,UAAU,KAAK,KAAK;AACpE;AACA;AACA,8CAA8C,SAAS,GAAG,QAAQ,KAAK,KAAK;AAC5E;AACA;AACA,iBAAiB,MAAM,qEAAiC;AACxD;AACA,sBAAsB,mEAA+B;AACrD;AACA;AACA;AACA;AACA,+DAA+D,UAAU,EAAE,OAAO;AAClF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB,WAAW,aAAa,UAAU;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,sBAAsB,mEAA+B;AACrD;AACA;AACA;AACA;AACA;AACA,aAAa,qEAAiC;AAC9C;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC/5ByD;AACI;AAC7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,mEAA+B;AAC7C,cAAc,qDAAa;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,mEAA+B;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,0DAAkB;AAC5C;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACO;AACP;AACA;AACA;AACA,gBAAgB,qDAAa;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,2CAAG;AACzB;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA,sBAAsB,gBAAgB;AACtC;AACA;AACA,gBAAgB,qDAAa;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA,sBAAsB,2CAAG;AACzB;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACO;AACP,6BAA6B,aAAa;AAC1C;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C,iFAAiF;AACjF;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,0BAA0B,UAAU,IAAI,oBAAoB,GAAG,oBAAoB,GAAG;AACtF;AACA;AACA,0BAA0B,oBAAoB,GAAG,oBAAoB;AACrE;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA,aAAa,mEAA+B;AAC5C;AACA,aAAa,qEAAiC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,mEAA+B;AAChD,gCAAgC,0BAA0B;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,qEAAiC;AAClD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA,gBAAgB;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,mEAA+B;AAChD,mCAAmC;AACnC;AACA;AACA;AACA,iBAAiB,qEAAiC;AAClD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB;AAChB;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA,aAAa,qDAAa;AAC1B;AACA;AACA,0BAA0B,mEAA+B;AACzD;AACA;AACA,kCAAkC,YAAY;AAC9C;AACA,wBAAwB,iDAAS;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+BAA+B,mEAA+B;AAC9D;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA,iCAAiC,mEAA+B;AAChE;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA,gCAAgC,mEAA+B;AAC/D;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACO;AACP,aAAa,qDAAa;AAC1B;AACA;AACA,0BAA0B,mEAA+B;AACzD;AACA,4BAA4B,UAAU;AACtC;AACA,oBAAoB,iDAAS;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8BAA8B,mEAA+B;AAC7D;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA,gCAAgC,mEAA+B;AAC/D;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA,+BAA+B,mEAA+B;AAC9D;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP,sBAAsB,mEAA+B;AACrD,wBAAwB,0BAA0B;AAClD;AACA;AACA;AACA;AACA,8BAA8B,qDAAa;AAC3C,yDAAyD,KAAK;AAC9D;AACA;AACA;AACA,oDAAoD,KAAK;AACzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4EAA4E,4BAA4B;AACxG;AACA;AACA;AACA;AACA;AACA,2EAA2E,4BAA4B;AACvG;AACA;AACA;AACA;AACA,6EAA6E,4BAA4B;AACzG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2BAA2B,mEAA+B;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qEAAqE,qDAAa;AAClF,sBAAsB,mEAA+B;AACrD;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,YAAY;AACtC;AACA,gBAAgB,iDAAS;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2BAA2B,MAAM,mEAA+B;AAChE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB,qEAAiC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B,KAAK,IAAI,kBAAkB;AACvD;AACA;AACA;AACA,qEAAqE,qDAAa;AAClF,sBAAsB,mEAA+B;AACrD;AACA;AACA,sBAAsB,mEAA+B;AACrD;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,mEAA+B;AACrD;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B,UAAU;AACtC;AACA,oBAAoB,iDAAS;AAC7B;AACA;AACA;AACA;AACA,8BAA8B,YAAY;AAC1C;AACA;AACA;AACA;AACA;AACA,sBAAsB,mEAA+B;AACrD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,mEAA+B;AACzD;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,mEAA+B;AACzD;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,mEAA+B;AACzD;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,mEAA+B;AACzD;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,mEAA+B;AACzD;AACA;AACA;AACA;AACA,0BAA0B,qEAAiC;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,mEAA+B;AACrD,0BAA0B,qDAAa;AACvC;AACA,8BAA8B,iDAAS;AACvC;AACA;AACA;AACA;AACA,gCAAgC,UAAU;AAC1C;AACA,yBAAyB,iDAAS;AAClC;AACA;AACA;AACA,+BAA+B,MAAM,mEAA+B;AACpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,qDAAa;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,mEAA+B;AACzD,4BAA4B,0BAA0B;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACO;AACP;AACA,0BAA0B,mEAA+B;AACzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA,0BAA0B,mEAA+B;AACzD,4BAA4B,0BAA0B;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA,0BAA0B,mEAA+B;AACzD,4BAA4B,0BAA0B;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,iDAAS;AACtB;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA,YAAY,iDAAS;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA,sBAAsB,qEAAiC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wBAAwB,cAAc;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACO;AACP;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,wBAAwB,cAAc;AACtC;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;ACxCA;AACA;AACA;AACO;AACP;AACA;AACO;AACP;AACA;AACO;AACP;AACA;AACA;AACA;AACA,sBAAsB,aAAa;AACnC;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qDAAqD,MAAM;AAC3D;AACA,aAAa;AACb;AACO;AACP;AACA,oBAAoB,eAAe;AACnC;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA,sBAAsB,iBAAiB;AACvC;AACA;AACA;AACA;AACA;AACA;;;;;;;UCjHA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;ACNyD;AACpC;AACD;AACuB;AACF;AACmC;AAC5E,2DAAmB;AACnB;AACA,WAAW,iDAAS;AACpB,CAAC;AACD,8DAAsB;AACtB,cAAc,sDAAc,KAAK,iDAAS;AAC1C;AACA;AACA,CAAC;AACD,wDAAY;AACZ,sDAAW","sources":["webpack://@calcit/ternary-tree/./lib/list.js","webpack://@calcit/ternary-tree/./lib/map.js","webpack://@calcit/ternary-tree/./lib/test-list.js","webpack://@calcit/ternary-tree/./lib/test-map.js","webpack://@calcit/ternary-tree/./lib/types.js","webpack://@calcit/ternary-tree/./lib/utils.js","webpack://@calcit/ternary-tree/webpack/bootstrap","webpack://@calcit/ternary-tree/webpack/runtime/define property getters","webpack://@calcit/ternary-tree/webpack/runtime/hasOwnProperty shorthand","webpack://@calcit/ternary-tree/webpack/runtime/make namespace object","webpack://@calcit/ternary-tree/./lib/main.js"],"sourcesContent":["import { TernaryTreeKind } from \"./types\";\nimport { dataEqual, divideTernarySizes, roughIntPow } from \"./utils\";\n// just get, will not compute recursively\nexport function getDepth(tree) {\n if (tree == null)\n return 0;\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return 1;\n case TernaryTreeKind.ternaryTreeBranch:\n return tree.depth;\n }\n}\nlet emptyBranch = null;\nlet isEmptyBranch = (x) => {\n if (x == null) {\n return true;\n }\n return x.size == 0;\n};\nfunction decideParentDepth(...xs) {\n let depth = 0;\n for (let i = 0; i < xs.length; i++) {\n let x = xs[i];\n let y = getDepth(x);\n if (y > depth) {\n depth = y;\n }\n }\n return depth + 1;\n}\nexport function makeTernaryTreeList(size, offset, xs) {\n switch (size) {\n case 0: {\n return { kind: TernaryTreeKind.ternaryTreeBranch, size: 0, depth: 1, left: emptyBranch, middle: emptyBranch, right: emptyBranch };\n }\n case 1:\n return xs[offset];\n case 2: {\n let left = xs[offset];\n let middle = xs[offset + 1];\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: listLen(left) + listLen(middle),\n left: left,\n middle: middle,\n right: emptyBranch,\n depth: decideParentDepth(left, middle),\n };\n return result;\n }\n case 3: {\n let left = xs[offset];\n let middle = xs[offset + 1];\n let right = xs[offset + 2];\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: listLen(left) + listLen(middle) + listLen(right),\n left: left,\n middle: middle,\n right: right,\n depth: decideParentDepth(left, middle, right),\n };\n return result;\n }\n default: {\n let divided = divideTernarySizes(size);\n let left = makeTernaryTreeList(divided.left, offset, xs);\n let middle = makeTernaryTreeList(divided.middle, offset + divided.left, xs);\n let right = makeTernaryTreeList(divided.right, offset + divided.left + divided.middle, xs);\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: listLen(left) + listLen(middle) + listLen(right),\n depth: decideParentDepth(left, middle, right),\n left: left,\n middle: middle,\n right: right,\n };\n return result;\n }\n }\n}\nexport function initTernaryTreeList(xs) {\n let ys = new Array(xs.length);\n let size = xs.length;\n for (let idx = 0; idx < size; idx++) {\n let x = xs[idx];\n ys[idx] = { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: x };\n }\n return makeTernaryTreeList(xs.length, 0, ys);\n}\n// from a slice of an existed array\nexport function initTernaryTreeListFromRange(xs, from, to) {\n let ys = new Array(xs.length);\n for (let idx = from; idx < to; idx++) {\n let x = xs[idx];\n ys[idx] = { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: x };\n }\n return makeTernaryTreeList(xs.length, 0, ys);\n}\nexport function initEmptyTernaryTreeList() {\n return { kind: TernaryTreeKind.ternaryTreeBranch, size: 0, depth: 1, middle: emptyBranch, left: emptyBranch, right: emptyBranch };\n}\nexport function listToString(tree) {\n return `TernaryTreeList[${tree.size}, ...]`;\n}\nexport function listLen(tree) {\n if (tree == null) {\n return 0;\n }\n else {\n return tree.size;\n }\n}\nfunction isLeaf(tree) {\n return tree.kind === TernaryTreeKind.ternaryTreeLeaf;\n}\nfunction isBranch(tree) {\n return tree.kind === TernaryTreeKind.ternaryTreeBranch;\n}\nexport function formatListInline(tree) {\n if (tree == null) {\n return \"_\";\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return `${tree.value}`;\n case TernaryTreeKind.ternaryTreeBranch:\n return \"(\" + formatListInline(tree.left) + \" \" + formatListInline(tree.middle) + \" \" + formatListInline(tree.right) + \")\";\n // \"(\" & tree.left.formatListInline & \" \" & tree.middle.formatListInline & \" \" & tree.right.formatListInline & \")@{tree.depth} \" & \"{tree.left.getDepth} {tree.middle.getDepth} {tree.right.getDepth}...\"\n }\n}\nexport function* listToItems(tree) {\n if (tree != null) {\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf: {\n yield tree.value;\n break;\n }\n case TernaryTreeKind.ternaryTreeBranch: {\n if (tree.left != null) {\n for (let x of listToItems(tree.left)) {\n yield x;\n }\n }\n if (tree.middle != null) {\n for (let x of listToItems(tree.middle)) {\n yield x;\n }\n }\n if (tree.right != null) {\n for (let x of listToItems(tree.right)) {\n yield x;\n }\n }\n break;\n }\n }\n }\n}\n// returns -1 if (not foun)\nexport function findIndex(tree, f) {\n if (tree == null) {\n return -1;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf: {\n if (f(tree.value)) {\n return 0;\n }\n else {\n return -1;\n }\n }\n case TernaryTreeKind.ternaryTreeBranch: {\n let tryLeft = findIndex(tree.left, f);\n if (tryLeft >= 0) {\n return tryLeft;\n }\n let tryMiddle = findIndex(tree.middle, f);\n if (tryMiddle >= 0) {\n return tryMiddle + listLen(tree.left);\n }\n let tryRight = findIndex(tree.right, f);\n if (tryRight >= 0) {\n return tryRight + listLen(tree.left) + listLen(tree.middle);\n }\n return -1;\n }\n }\n}\n// returns -1 if (not foun)\nexport function indexOf(tree, item) {\n if (tree == null) {\n return -1;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n if (dataEqual(item, tree.value)) {\n return 0;\n }\n default:\n return -1;\n case TernaryTreeKind.ternaryTreeBranch:\n let tryLeft = indexOf(tree.left, item);\n if (tryLeft >= 0) {\n return tryLeft;\n }\n let tryMiddle = indexOf(tree.middle, item);\n if (tryMiddle >= 0) {\n return tryMiddle + listLen(tree.left);\n }\n let tryRight = indexOf(tree.right, item);\n if (tryRight >= 0) {\n return tryRight + listLen(tree.left) + listLen(tree.middle);\n }\n return -1;\n }\n}\nfunction writeLeavesArray(tree, acc, idx) {\n if (tree == null) {\n //\n }\n else {\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf: {\n acc[idx.value] = tree;\n idx.value = idx.value + 1;\n break;\n }\n case TernaryTreeKind.ternaryTreeBranch: {\n if (tree.left != null) {\n writeLeavesArray(tree.left, acc, idx);\n }\n if (tree.middle != null) {\n writeLeavesArray(tree.middle, acc, idx);\n }\n if (tree.right != null) {\n writeLeavesArray(tree.right, acc, idx);\n }\n break;\n }\n default: {\n throw new Error(\"Unknown\");\n }\n }\n }\n}\nfunction toLeavesArray(tree) {\n let acc = new Array(listLen(tree));\n let counter = { value: 0 };\n writeLeavesArray(tree, acc, counter);\n return acc;\n}\nexport function* indexToItems(tree) {\n for (let idx = 0; idx < listLen(tree); idx++) {\n yield listGet(tree, idx);\n }\n}\nexport function* listToPairs(tree) {\n let idx = 0;\n for (let x of listToItems(tree)) {\n yield [idx, x];\n idx = idx + 1;\n }\n}\nexport function listGet(originalTree, originalIdx) {\n let tree = originalTree;\n let idx = originalIdx;\n while (tree != null) {\n if (idx < 0) {\n throw new Error(\"Cannot index negative number\");\n }\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (idx === 0) {\n return tree.value;\n }\n else {\n throw new Error(`Cannot get from leaf with index ${idx}`);\n }\n }\n if (idx > tree.size - 1) {\n throw new Error(\"Index too large\");\n }\n let leftSize = tree.left == null ? 0 : tree.left.size;\n let middleSize = tree.middle == null ? 0 : tree.middle.size;\n let rightSize = tree.right == null ? 0 : tree.right.size;\n if (leftSize + middleSize + rightSize !== tree.size) {\n throw new Error(\"tree.size does not match sum case branch sizes\");\n }\n if (idx <= leftSize - 1) {\n tree = tree.left;\n }\n else if (idx <= leftSize + middleSize - 1) {\n tree = tree.middle;\n idx = idx - leftSize;\n }\n else {\n tree = tree.right;\n idx = idx - leftSize - middleSize;\n }\n }\n throw new Error(`Failed to get ${idx}`);\n}\nexport function first(tree) {\n if (listLen(tree) > 0) {\n return listGet(tree, 0);\n }\n else {\n throw new Error(\"Cannot get from empty list\");\n }\n}\nexport function last(tree) {\n if (listLen(tree) > 0) {\n return listGet(tree, listLen(tree) - 1);\n }\n else {\n throw new Error(\"Cannot get from empty list\");\n }\n}\nexport function assocList(tree, idx, item) {\n if (idx < 0) {\n throw new Error(\"Cannot index negative number\");\n }\n if (idx > tree.size - 1) {\n throw new Error(\"Index too large\");\n }\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (idx === 0) {\n return { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item };\n }\n else {\n throw new Error(`Cannot get from leaf with index ${idx}`);\n }\n }\n let leftSize = listLen(tree.left);\n let middleSize = listLen(tree.middle);\n let rightSize = listLen(tree.right);\n if (leftSize + middleSize + rightSize !== tree.size)\n throw new Error(\"tree.size does not match sum case branch sizes\");\n if (idx <= leftSize - 1) {\n let changedBranch = assocList(tree.left, idx, item);\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size,\n depth: decideParentDepth(changedBranch, tree.middle, tree.right),\n left: changedBranch,\n middle: tree.middle,\n right: tree.right,\n };\n return result;\n }\n else if (idx <= leftSize + middleSize - 1) {\n let changedBranch = assocList(tree.middle, idx - leftSize, item);\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size,\n depth: decideParentDepth(tree.left, changedBranch, tree.right),\n left: tree.left,\n middle: changedBranch,\n right: tree.right,\n };\n return result;\n }\n else {\n let changedBranch = assocList(tree.right, idx - leftSize - middleSize, item);\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size,\n depth: decideParentDepth(tree.left, tree.middle, changedBranch),\n left: tree.left,\n middle: tree.middle,\n right: changedBranch,\n };\n return result;\n }\n}\nexport function dissocList(tree, idx) {\n if (tree == null) {\n throw new Error(\"dissoc does not work on null\");\n }\n if (idx < 0) {\n throw new Error(`Index is negative ${idx}`);\n }\n if (listLen(tree) === 0) {\n throw new Error(\"Cannot remove from empty list\");\n }\n if (idx > listLen(tree) - 1) {\n throw new Error(`Index too large ${idx}`);\n }\n if (listLen(tree) === 1) {\n return emptyBranch;\n }\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n throw new Error(\"dissoc should be handled at branches\");\n }\n let leftSize = listLen(tree.left);\n let middleSize = listLen(tree.middle);\n let rightSize = listLen(tree.right);\n if (leftSize + middleSize + rightSize !== tree.size) {\n throw new Error(\"tree.size does not match sum from branch sizes\");\n }\n let result = emptyBranch;\n if (idx <= leftSize - 1) {\n let changedBranch = dissocList(tree.left, idx);\n if (changedBranch == null || changedBranch.size === 0) {\n result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size - 1,\n depth: decideParentDepth(tree.middle, tree.right),\n left: tree.middle,\n middle: tree.right,\n right: emptyBranch,\n };\n }\n else {\n result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size - 1,\n depth: decideParentDepth(changedBranch, tree.middle, tree.right),\n left: changedBranch,\n middle: tree.middle,\n right: tree.right,\n };\n }\n }\n else if (idx <= leftSize + middleSize - 1) {\n let changedBranch = dissocList(tree.middle, idx - leftSize);\n if (changedBranch == null || changedBranch.size === 0) {\n result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size - 1,\n depth: decideParentDepth(tree.left, changedBranch, tree.right),\n left: tree.left,\n middle: tree.right,\n right: emptyBranch,\n };\n }\n else {\n result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size - 1,\n depth: decideParentDepth(tree.left, changedBranch, tree.right),\n left: tree.left,\n middle: changedBranch,\n right: tree.right,\n };\n }\n }\n else {\n let changedBranch = dissocList(tree.right, idx - leftSize - middleSize);\n if (changedBranch == null || changedBranch.size === 0) {\n changedBranch = emptyBranch;\n }\n result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size - 1,\n depth: decideParentDepth(tree.left, tree.middle, changedBranch),\n left: tree.left,\n middle: tree.middle,\n right: changedBranch,\n };\n }\n if (result.middle == null) {\n return result.left;\n }\n return result;\n}\nexport function rest(tree) {\n if (tree == null) {\n throw new Error(\"Cannot call rest on null\");\n }\n if (listLen(tree) < 1) {\n throw new Error(\"Cannot call rest on empty list\");\n }\n return dissocList(tree, 0);\n}\nexport function butlast(tree) {\n if (tree == null) {\n throw new Error(\"Cannot call butlast on null\");\n }\n if (listLen(tree) < 1) {\n throw new Error(\"Cannot call butlast on empty list\");\n }\n return dissocList(tree, listLen(tree) - 1);\n}\nexport function insert(tree, idx, item, after = false) {\n if (tree == null) {\n throw new Error(\"Cannot insert into null\");\n }\n if (listLen(tree) === 0) {\n throw new Error(\"Empty node is not a correct position for inserting\");\n }\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (after) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n depth: getDepth(tree) + 1,\n size: 2,\n left: tree,\n middle: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n right: emptyBranch,\n };\n return result;\n }\n else {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n depth: getDepth(tree) + 1,\n size: 2,\n left: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n middle: tree,\n right: emptyBranch,\n };\n return result;\n }\n }\n if (listLen(tree) === 1) {\n if (after) {\n // in compact mode, values placed at left\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: 2,\n depth: 2,\n left: tree.left,\n middle: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n right: emptyBranch,\n };\n return result;\n }\n else {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: 2,\n depth: getDepth(tree.middle) + 1,\n left: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n middle: tree.left,\n right: emptyBranch,\n };\n return result;\n }\n }\n if (listLen(tree) === 2 && tree.middle != null) {\n if (after) {\n if (idx === 0) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: 3,\n depth: 2,\n left: tree.left,\n middle: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n right: tree.middle,\n };\n return result;\n }\n if (idx === 1) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: 3,\n depth: 2,\n left: tree.left,\n middle: tree.middle,\n right: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n };\n return result;\n }\n else {\n throw new Error(\"cannot insert after position 2 since only 2 elements here\");\n }\n }\n else {\n if (idx === 0) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: 3,\n depth: 2,\n left: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n middle: tree.left,\n right: tree.middle,\n };\n return result;\n }\n else if (idx === 1) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: 3,\n depth: 2,\n left: tree.left,\n middle: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n right: tree.middle,\n };\n return result;\n }\n else {\n throw new Error(\"cannot insert before position 2 since only 2 elements here\");\n }\n }\n }\n let leftSize = listLen(tree.left);\n let middleSize = listLen(tree.middle);\n let rightSize = listLen(tree.right);\n if (leftSize + middleSize + rightSize !== tree.size) {\n throw new Error(\"tree.size does not match sum case branch sizes\");\n }\n // echo \"picking: \", idx, \" \", leftSize, \" \", middleSize, \" \", rightSize\n if (idx === 0 && !after) {\n if (listLen(tree.left) >= listLen(tree.middle) && listLen(tree.left) >= listLen(tree.right)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size + 1,\n depth: tree.depth + 1,\n left: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n middle: tree,\n right: emptyBranch,\n };\n return result;\n }\n }\n if (idx === listLen(tree) - 1 && after) {\n if (listLen(tree.right) >= listLen(tree.middle) && listLen(tree.right) >= listLen(tree.left)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size + 1,\n depth: tree.depth + 1,\n left: tree,\n middle: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n right: emptyBranch,\n };\n return result;\n }\n }\n if (after && idx === listLen(tree) - 1 && rightSize === 0 && middleSize >= leftSize) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size + 1,\n depth: tree.depth,\n left: tree.left,\n middle: tree.middle,\n right: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n };\n return result;\n }\n if (!after && idx === 0 && rightSize === 0 && middleSize >= rightSize) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size + 1,\n depth: tree.depth,\n left: { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },\n middle: tree.left,\n right: tree.middle,\n };\n return result;\n }\n if (idx <= leftSize - 1) {\n let changedBranch = insert(tree.left, idx, item, after);\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size + 1,\n depth: decideParentDepth(changedBranch, tree.middle, tree.right),\n left: changedBranch,\n middle: tree.middle,\n right: tree.right,\n };\n return result;\n }\n else if (idx <= leftSize + middleSize - 1) {\n let changedBranch = insert(tree.middle, idx - leftSize, item, after);\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size + 1,\n depth: decideParentDepth(tree.left, changedBranch, tree.right),\n left: tree.left,\n middle: changedBranch,\n right: tree.right,\n };\n return result;\n }\n else {\n let changedBranch = insert(tree.right, idx - leftSize - middleSize, item, after);\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size + 1,\n depth: decideParentDepth(tree.left, tree.middle, changedBranch),\n left: tree.left,\n middle: tree.middle,\n right: changedBranch,\n };\n return result;\n }\n}\nexport function assocBefore(tree, idx, item, after = false) {\n return insert(tree, idx, item, false);\n}\nexport function assocAfter(tree, idx, item, after = false) {\n return insert(tree, idx, item, true);\n}\n// this function mutates original tree to make it more balanced\nexport function forceListInplaceBalancing(tree) {\n if (tree.kind === TernaryTreeKind.ternaryTreeBranch) {\n // echo \"Force inplace balancing case list: \", tree.size\n let ys = toLeavesArray(tree);\n let newTree = makeTernaryTreeList(ys.length, 0, ys);\n // let newTree = initTernaryTreeList(ys)\n tree.left = newTree.left;\n tree.middle = newTree.middle;\n tree.right = newTree.right;\n tree.depth = decideParentDepth(tree.left, tree.middle, tree.right);\n }\n else {\n //\n }\n}\n// TODO, need better strategy for detecting\nfunction maybeReblance(tree) {\n let currentDepth = getDepth(tree);\n if (currentDepth > 50) {\n if (roughIntPow(3, currentDepth - 50) > tree.size) {\n forceListInplaceBalancing(tree);\n }\n }\n}\nexport function prepend(tree, item, disableBalancing = false) {\n if (tree == null || listLen(tree) === 0) {\n return { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item };\n }\n let result = insert(tree, 0, item, false);\n if (!disableBalancing) {\n maybeReblance(result);\n }\n return result;\n}\nexport function append(tree, item, disableBalancing = false) {\n if (tree == null || listLen(tree) === 0) {\n return { kind: TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item };\n }\n let result = insert(tree, listLen(tree) - 1, item, true);\n if (!disableBalancing) {\n maybeReblance(result);\n }\n return result;\n}\nexport function concat(...xsGroups) {\n xsGroups = xsGroups.filter((xs) => listLen(xs) > 0);\n let result = makeTernaryTreeList(xsGroups.length, 0, xsGroups);\n maybeReblance(result);\n return result;\n}\nexport function sameListShape(xs, ys) {\n if (xs == null) {\n if (ys == null) {\n return true;\n }\n else {\n return false;\n }\n }\n if (ys == null) {\n return false;\n }\n if (listLen(xs) !== listLen(ys)) {\n return false;\n }\n if (xs.kind !== ys.kind) {\n return false;\n }\n if (xs.kind === TernaryTreeKind.ternaryTreeLeaf && ys.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (!dataEqual(xs.value, ys.value)) {\n return false;\n }\n else {\n return true;\n }\n }\n if (xs.kind === TernaryTreeKind.ternaryTreeBranch && ys.kind === TernaryTreeKind.ternaryTreeBranch) {\n if (!sameListShape(xs.left, ys.left))\n return false;\n if (!sameListShape(xs.middle, ys.middle))\n return false;\n if (!sameListShape(xs.right, ys.right))\n return false;\n return true;\n }\n return false;\n}\nexport function listEqual(xs, ys) {\n if (xs === ys) {\n return true;\n }\n if (listLen(xs) !== listLen(ys)) {\n return false;\n }\n for (let idx = 0; idx < listLen(xs); idx++) {\n if (!dataEqual(listGet(xs, idx), listGet(ys, idx))) {\n return false;\n }\n }\n return true;\n}\nexport function checkListStructure(tree) {\n if (tree == null) {\n return true;\n }\n else {\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n if (tree.size !== 1) {\n throw new Error(`Bad size at node ${formatListInline(tree)}`);\n }\n break;\n case TernaryTreeKind.ternaryTreeBranch: {\n if (tree.size !== listLen(tree.left) + listLen(tree.middle) + listLen(tree.right)) {\n throw new Error(`Bad size at branch ${formatListInline(tree)}`);\n }\n if (tree.depth !== decideParentDepth(tree.left, tree.middle, tree.right)) {\n let x = decideParentDepth(tree.left, tree.middle, tree.right);\n throw new Error(`Bad depth at branch ${formatListInline(tree)}`);\n }\n checkListStructure(tree.left);\n checkListStructure(tree.middle);\n checkListStructure(tree.right);\n break;\n }\n }\n return true;\n }\n}\n// excludes value at endIdx, kept aligned with JS & Clojure\nexport function slice(tree, startIdx, endIdx) {\n // echo \"slice {tree.formatListInline}: {startIdx}..{endIdx}\"\n if (endIdx > listLen(tree)) {\n throw new Error(\"Slice range too large {endIdx} for {tree}\");\n }\n if (startIdx < 0) {\n throw new Error(\"Slice range too small {startIdx} for {tree}\");\n }\n if (startIdx > endIdx) {\n throw new Error(\"Invalid slice range {startIdx}..{endIdx} for {tree}\");\n }\n if (startIdx === endIdx) {\n return { kind: TernaryTreeKind.ternaryTreeBranch, size: 0, depth: 0 };\n }\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf)\n if (startIdx === 0 && endIdx === 1) {\n return tree;\n }\n else {\n throw new Error(`Invalid slice range for a leaf: ${startIdx} ${endIdx}`);\n }\n if (startIdx === 0 && endIdx === listLen(tree)) {\n return tree;\n }\n let leftSize = listLen(tree.left);\n let middleSize = listLen(tree.middle);\n let rightSize = listLen(tree.right);\n // echo \"sizes: {leftSize} {middleSize} {rightSize}\"\n if (startIdx >= leftSize + middleSize) {\n return slice(tree.right, startIdx - leftSize - middleSize, endIdx - leftSize - middleSize);\n }\n if (startIdx >= leftSize)\n if (endIdx <= leftSize + middleSize) {\n return slice(tree.middle, startIdx - leftSize, endIdx - leftSize);\n }\n else {\n let middleCut = slice(tree.middle, startIdx - leftSize, middleSize);\n let rightCut = slice(tree.right, 0, endIdx - leftSize - middleSize);\n return concat(middleCut, rightCut);\n }\n if (endIdx <= leftSize) {\n return slice(tree.left, startIdx, endIdx);\n }\n if (endIdx <= leftSize + middleSize) {\n let leftCut = slice(tree.left, startIdx, leftSize);\n let middleCut = slice(tree.middle, 0, endIdx - leftSize);\n return concat(leftCut, middleCut);\n }\n if (endIdx <= leftSize + middleSize + rightSize) {\n let leftCut = slice(tree.left, startIdx, leftSize);\n let rightCut = slice(tree.right, 0, endIdx - leftSize - middleSize);\n return concat(concat(leftCut, tree.middle), rightCut);\n }\n throw new Error(\"Unknown\");\n}\nexport function reverse(tree) {\n if (tree == null) {\n return tree;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return tree;\n case TernaryTreeKind.ternaryTreeBranch: {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size,\n depth: tree.depth,\n left: reverse(tree.right),\n middle: reverse(tree.middle),\n right: reverse(tree.left),\n };\n return result;\n }\n }\n}\nexport function listMapValues(tree, f) {\n if (tree == null) {\n return tree;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf: {\n let result = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n size: tree.size,\n value: f(tree.value),\n };\n return result;\n }\n case TernaryTreeKind.ternaryTreeBranch: {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n size: tree.size,\n depth: tree.depth,\n left: tree.left == null ? emptyBranch : listMapValues(tree.left, f),\n middle: tree.middle == null ? emptyBranch : listMapValues(tree.middle, f),\n right: tree.right == null ? emptyBranch : listMapValues(tree.right, f),\n };\n return result;\n }\n }\n}\n","import { TernaryTreeKind, hashGenerator } from \"./types\";\nimport { divideTernarySizes, cmp, dataEqual } from \"./utils\";\nlet emptyBranch = null;\nlet nilResult = null;\nfunction getMax(tree) {\n if (tree == null) {\n throw new Error(\"Cannot find max hash of nil\");\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return tree.hash;\n case TernaryTreeKind.ternaryTreeBranch:\n return tree.maxHash;\n default:\n throw new Error(\"Unknown\");\n }\n}\nfunction getMin(tree) {\n if (tree == null) {\n throw new Error(\"Cannot find min hash of nil\");\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return tree.hash;\n case TernaryTreeKind.ternaryTreeBranch:\n return tree.minHash;\n default:\n throw new Error(\"Unknown\");\n }\n}\nexport function getMapDepth(tree) {\n // console.log( \"calling...\", tree)\n if (tree == null) {\n return 0;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return 1;\n case TernaryTreeKind.ternaryTreeBranch:\n return Math.max(getMapDepth(tree.left), getMapDepth(tree.middle), getMapDepth(tree.right)) + 1;\n default:\n throw new Error(\"Unknown\");\n }\n}\nfunction createLeaf(k, v) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: hashGenerator(k),\n elements: [[k, v]],\n };\n return result;\n}\nfunction createLeafFromHashEntry(item) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: item.hash,\n elements: item.pairs,\n };\n return result;\n}\n// this proc is not exported, pick up next proc as the entry.\n// pairs must be sorted before passing to proc.\nfunction makeTernaryTreeMap(size, offset, xs) {\n switch (size) {\n case 0: {\n let result = emptyBranch;\n return result;\n }\n case 1: {\n let leftPair = xs[offset];\n let result = createLeafFromHashEntry(leftPair);\n return result;\n }\n case 2: {\n let leftPair = xs[offset];\n let middlePair = xs[offset + 1];\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: middlePair.hash,\n minHash: leftPair.hash,\n left: createLeafFromHashEntry(leftPair),\n middle: createLeafFromHashEntry(middlePair),\n right: emptyBranch,\n depth: 1,\n };\n return result;\n }\n case 3: {\n let leftPair = xs[offset];\n let middlePair = xs[offset + 1];\n let rightPair = xs[offset + 2];\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: rightPair.hash,\n minHash: leftPair.hash,\n left: createLeafFromHashEntry(leftPair),\n middle: createLeafFromHashEntry(middlePair),\n right: createLeafFromHashEntry(rightPair),\n depth: 1,\n };\n return result;\n }\n default: {\n let divided = divideTernarySizes(size);\n let left = makeTernaryTreeMap(divided.left, offset, xs);\n let middle = makeTernaryTreeMap(divided.middle, offset + divided.left, xs);\n let right = makeTernaryTreeMap(divided.right, offset + divided.left + divided.middle, xs);\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: getMax(right),\n minHash: getMin(left),\n left: left,\n middle: middle,\n right: right,\n depth: Math.max(getMapDepth(left), getMapDepth(middle), getMapDepth(right)) + 1,\n };\n return result;\n }\n }\n}\nexport function initTernaryTreeMapFromHashEntries(xs) {\n return makeTernaryTreeMap(xs.length, 0, xs);\n}\nexport function initTernaryTreeMap(t) {\n let groupBuffers = new Map();\n let xs = [];\n for (let [k, v] of t) {\n let h = hashGenerator(k);\n if (groupBuffers.has(h)) {\n let branch = groupBuffers.get(h);\n if (branch != null) {\n branch.push([k, v]);\n }\n else {\n throw new Error(\"Expected referece to pairs\");\n }\n }\n else {\n let pairs = [[k, v]];\n groupBuffers.set(h, pairs);\n xs.push({\n hash: h,\n pairs,\n });\n }\n }\n for (let [k, v] of groupBuffers) {\n if (v != null) {\n }\n else {\n throw new Error(\"Expected reference to paris\");\n }\n }\n // MUTABLE in-place sort\n xs.sort((a, b) => cmp(a.hash, b.hash));\n let result = initTernaryTreeMapFromHashEntries(xs);\n // checkMapStructure(result);\n return result;\n}\n// use for..in for performance\nexport function initTernaryTreeMapFromArray(t) {\n let groupBuffers = {};\n let xs = [];\n for (let idx = 0; idx < t.length; idx++) {\n let k = t[idx][0];\n let v = t[idx][1];\n let h = hashGenerator(k);\n if (groupBuffers[h] != null) {\n let branch = groupBuffers[h];\n if (branch != null) {\n branch.push([k, v]);\n }\n else {\n throw new Error(\"Expected referece to pairs\");\n }\n }\n else {\n let pairs = [[k, v]];\n groupBuffers[h] = pairs;\n xs.push({\n hash: h,\n pairs: pairs,\n });\n }\n }\n // MUTABLE in-place sort\n xs.sort((a, b) => cmp(a.hash, b.hash));\n let result = initTernaryTreeMapFromHashEntries(xs);\n // checkMapStructure(result);\n return result;\n}\n// for empty map\nexport function initEmptyTernaryTreeMap() {\n let result = emptyBranch;\n return result;\n}\nexport function mapToString(tree) {\n return `TernaryTreeMap[${mapLen(tree)}, ...]`;\n}\nexport function mapLen(tree) {\n if (tree == null) {\n return 0;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return tree.elements.length;\n case TernaryTreeKind.ternaryTreeBranch:\n return mapLen(tree.left) + mapLen(tree.middle) + mapLen(tree.right); // TODO\n default:\n throw new Error(\"Unknown\");\n }\n}\n// when size succeeds bound, no longer counting, faster than traversing whole tree\nexport function mapLenBound(tree, bound) {\n if (tree == null) {\n return 0;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return tree.elements.length;\n case TernaryTreeKind.ternaryTreeBranch:\n let ret = mapLenBound(tree.left, bound);\n if (ret > bound) {\n return ret;\n }\n ret = ret + mapLenBound(tree.middle, bound);\n if (ret > bound) {\n return ret;\n }\n ret = ret + mapLenBound(tree.right, bound);\n return ret;\n default:\n throw new Error(\"Unknown\");\n }\n}\nexport function formatMapInline(tree, withHash = false) {\n if (tree == null) {\n return \"_\";\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n if (withHash) {\n return `${tree.hash}->${tree.elements[0][0]}:${tree.elements[0][1]}`; // TODO show whole list\n }\n else {\n return `${tree.elements[0][0]}:${tree.elements[0][1]}`;\n }\n case TernaryTreeKind.ternaryTreeBranch: {\n return \"(\" + formatMapInline(tree.left, withHash) + \" \" + formatMapInline(tree.middle, withHash) + \" \" + formatMapInline(tree.right, withHash) + \")\";\n }\n default:\n throw new Error(\"Unknown\");\n }\n}\nexport function isMapEmpty(tree) {\n if (tree == null) {\n return true;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return false;\n case TernaryTreeKind.ternaryTreeBranch:\n return tree.left == null && tree.middle == null && tree.right == null;\n default:\n throw new Error(\"Unknown\");\n }\n}\nexport function isMapOfOne(tree, counted = 0) {\n if (tree == null) {\n return true;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf:\n return false;\n case TernaryTreeKind.ternaryTreeBranch:\n return tree.left == null && tree.middle == null && tree.right == null;\n default:\n throw new Error(\"Unknown\");\n }\n}\nfunction collectHashSortedArray(tree, acc, idx) {\n if (tree == null || isMapEmpty(tree)) {\n // discard\n }\n else {\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf: {\n for (let i = 0; i < tree.elements.length; i++) {\n let item = tree.elements[i];\n acc[idx.value] = item;\n idx.value = idx.value + 1;\n }\n break;\n }\n case TernaryTreeKind.ternaryTreeBranch: {\n collectHashSortedArray(tree.left, acc, idx);\n collectHashSortedArray(tree.middle, acc, idx);\n collectHashSortedArray(tree.right, acc, idx);\n break;\n }\n default:\n throw new Error(\"Unknown\");\n }\n }\n}\n// sorted by hash(tree.key)\nexport function toHashSortedPairs(tree) {\n let acc = new Array(mapLen(tree));\n let idx = { value: 0 };\n collectHashSortedArray(tree, acc, idx);\n return acc;\n}\nfunction collectOrderedHashEntries(tree, acc, idx) {\n if (tree == null || isMapEmpty(tree)) {\n // discard\n }\n else {\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf: {\n acc[idx.value] = { hash: tree.hash, pairs: tree.elements };\n idx.value = idx.value + 1;\n break;\n }\n case TernaryTreeKind.ternaryTreeBranch: {\n collectOrderedHashEntries(tree.left, acc, idx);\n collectOrderedHashEntries(tree.middle, acc, idx);\n collectOrderedHashEntries(tree.right, acc, idx);\n break;\n }\n default: {\n throw new Error(\"Unknown\");\n }\n }\n }\n}\n// for reusing leaves during rebalancing\nfunction toOrderedHashEntries(tree) {\n let acc = new Array(mapLen(tree));\n let idx = { value: 0 };\n collectOrderedHashEntries(tree, acc, idx);\n return acc;\n}\nexport function contains(originalTree, item) {\n if (originalTree == null) {\n return false;\n }\n // TODO\n // reduce redundant computation by reusing hash result\n let hx = hashGenerator(item);\n let tree = originalTree;\n whileLoop: while (tree != null) {\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (hx === tree.hash) {\n let size = tree.elements.length;\n for (let idx = 0; idx < size; idx++) {\n let pair = tree.elements[idx];\n if (dataEqual(pair[0], item)) {\n return true;\n }\n }\n }\n return false;\n }\n // echo \"looking for: \", hx, \" \", item, \" in \", tree.formatInline(true)\n if (tree.left == null) {\n return false;\n }\n if (tree.left.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (hx < tree.left.hash) {\n return false;\n }\n if (tree.left.hash === hx) {\n tree = tree.left;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n else {\n if (hx < tree.left.minHash) {\n return false;\n }\n if (hx <= tree.left.maxHash) {\n tree = tree.left;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n if (tree.middle == null) {\n return false;\n }\n if (tree.middle.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (hx < tree.middle.hash) {\n return false;\n }\n if (tree.middle.hash === hx) {\n tree = tree.middle;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n else {\n if (hx < tree.middle.minHash) {\n return false;\n }\n if (hx <= tree.middle.maxHash) {\n tree = tree.middle;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n if (tree.right == null) {\n return false;\n }\n if (tree.right.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (hx < tree.right.hash) {\n return false;\n }\n if (tree.right.hash === hx) {\n tree = tree.right;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n else {\n if (hx < tree.right.minHash) {\n return false;\n }\n if (hx <= tree.right.maxHash) {\n tree = tree.right;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n return false;\n }\n return false;\n}\nexport function mapGetDefault(originalTree, item, v0) {\n let hx = hashGenerator(item);\n let tree = originalTree;\n whileLoop: while (tree != null) {\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n let size = tree.elements.length;\n for (let i = 0; i < size; i++) {\n let pair = tree.elements[i];\n if (dataEqual(pair[0], item)) {\n return pair[1];\n }\n }\n return v0;\n }\n // echo \"looking for: \", hx, \" \", item, \" in \", tree.formatInline\n if (tree.left == null) {\n return v0;\n }\n if (tree.left.kind == TernaryTreeKind.ternaryTreeLeaf) {\n if (hx < tree.left.hash) {\n return v0;\n }\n if (tree.left.hash === hx) {\n tree = tree.left;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n else {\n if (hx < tree.left.minHash) {\n return v0;\n }\n if (hx <= tree.left.maxHash) {\n tree = tree.left;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n if (tree.middle == null) {\n return v0;\n }\n if (tree.middle.kind == TernaryTreeKind.ternaryTreeLeaf) {\n if (hx < tree.middle.hash) {\n return v0;\n }\n if (tree.middle.hash === hx) {\n tree = tree.middle;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n else {\n if (hx < tree.middle.minHash) {\n return v0;\n }\n if (hx <= tree.middle.maxHash) {\n tree = tree.middle;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n if (tree.right == null) {\n return v0;\n }\n if (tree.right.kind == TernaryTreeKind.ternaryTreeLeaf) {\n if (hx < tree.right.hash) {\n return v0;\n }\n if (tree.right.hash === hx) {\n tree = tree.right;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n else {\n if (hx < tree.right.minHash) {\n return v0;\n }\n if (hx <= tree.right.maxHash) {\n tree = tree.right;\n continue whileLoop; // notice, it jumps to while loop\n }\n }\n return v0;\n }\n return v0;\n}\n// leaves on the left has smaller hashes\n// TODO check sizes, hashes\nexport function checkMapStructure(tree) {\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n for (let i = 0; i < tree.elements.length; i++) {\n let pair = tree.elements[i];\n if (pair.length !== 2) {\n throw new Error(\"Expected pair to br [k,v] :\" + pair);\n }\n if (tree.hash !== hashGenerator(pair[0])) {\n throw new Error(`Bad hash at leaf node ${tree}`);\n }\n }\n if (mapLenBound(tree, 2) !== 1) {\n throw new Error(`Bad len at leaf node ${tree}`);\n }\n }\n else {\n if (tree.left == null) {\n if (tree.middle != null) {\n throw new Error(\"Layout is not compact\");\n }\n if (tree.middle != null) {\n throw new Error(\"Layout is not compact\");\n }\n }\n if (tree.middle == null) {\n if (tree.right != null) {\n throw new Error(\"Layout is not compact\");\n }\n }\n if (tree.left != null && tree.middle != null) {\n if (getMax(tree.left) >= getMin(tree.middle)) {\n throw new Error(`Wrong hash order at left/middle branches ${formatMapInline(tree, true)}`);\n }\n }\n if (tree.left != null && tree.right != null) {\n if (getMax(tree.left) >= getMin(tree.right)) {\n console.log(getMax(tree.left), getMin(tree.right));\n throw new Error(`Wrong hash order at left/right branches ${formatMapInline(tree, true)}`);\n }\n }\n if (tree.middle != null && tree.right != null) {\n if (getMax(tree.middle) >= getMin(tree.right)) {\n throw new Error(`Wrong hash order at middle/right branches ${formatMapInline(tree, true)}`);\n }\n }\n if (tree.left != null) {\n checkMapStructure(tree.left);\n }\n if (tree.middle != null) {\n checkMapStructure(tree.middle);\n }\n if (tree.right != null) {\n checkMapStructure(tree.right);\n }\n }\n return true;\n}\nfunction rangeContainsHash(tree, thisHash) {\n if (tree == null) {\n return false;\n }\n else if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n return tree.hash === thisHash;\n }\n else {\n return thisHash >= tree.minHash && thisHash <= tree.maxHash;\n }\n}\nfunction assocExisted(tree, key, item, thisHash = null) {\n if (tree == null || isMapEmpty(tree)) {\n throw new Error(\"Cannot call assoc on nil\");\n }\n thisHash = thisHash !== null && thisHash !== void 0 ? thisHash : hashGenerator(key);\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (tree.hash !== thisHash) {\n throw new Error(\"Expected hashes to be identical, otherwise element is missing\");\n }\n let newPairs = new Array(tree.elements.length);\n let replaced = false;\n let size = tree.elements.length;\n for (let idx = 0; idx < size; idx++) {\n let pair = tree.elements[idx];\n if (dataEqual(pair[0], key)) {\n newPairs[idx] = [key, item];\n replaced = true;\n }\n else {\n newPairs[idx] = pair;\n }\n }\n if (replaced) {\n let result = { kind: TernaryTreeKind.ternaryTreeLeaf, hash: thisHash, elements: newPairs };\n return result;\n }\n else {\n throw new Error(\"Unexpected missing hash in assoc, invalid branch\");\n }\n }\n if (thisHash < tree.minHash)\n throw new Error(\"Unexpected missing hash in assoc, hash too small\");\n else if (thisHash > tree.maxHash)\n throw new Error(\"Unexpected missing hash in assoc, hash too large\");\n if (tree.left == null) {\n throw new Error(\"Unexpected missing hash in assoc, found not branch\");\n }\n if (rangeContainsHash(tree.left, thisHash)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: assocExisted(tree.left, key, item, thisHash),\n middle: tree.middle,\n right: tree.right,\n depth: 0, // TODO\n };\n return result;\n }\n if (tree.middle == null) {\n throw new Error(\"Unexpected missing hash in assoc, found not branch\");\n }\n if (rangeContainsHash(tree.middle, thisHash)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: assocExisted(tree.middle, key, item, thisHash),\n right: tree.right,\n depth: 0, // TODO\n };\n return result;\n }\n if (tree.right == null) {\n throw new Error(\"Unexpected missing hash in assoc, found not branch\");\n }\n if (rangeContainsHash(tree.right, thisHash)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: tree.middle,\n right: assocExisted(tree.right, key, item, thisHash),\n depth: 0, // TODO\n };\n return result;\n }\n throw new Error(\"Unexpected missing hash in assoc, found not branch\");\n}\nfunction assocNew(tree, key, item, thisHash = null) {\n // echo fmt\"assoc new: {key} to {tree.formatInline}\"\n if (tree == null || isMapEmpty(tree)) {\n return createLeaf(key, item);\n }\n thisHash = thisHash !== null && thisHash !== void 0 ? thisHash : hashGenerator(key);\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (thisHash > tree.hash) {\n let childBranch = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: thisHash,\n elements: [[key, item]],\n };\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: thisHash,\n minHash: tree.hash,\n left: tree,\n middle: childBranch,\n right: emptyBranch,\n depth: 0, // TODO\n };\n return result;\n }\n else if (thisHash < tree.hash) {\n let childBranch = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: thisHash,\n elements: [[key, item]],\n };\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.hash,\n minHash: thisHash,\n left: childBranch,\n middle: tree,\n right: emptyBranch,\n depth: 0, // TODO\n };\n return result;\n }\n else {\n let size = tree.elements.length;\n for (let i = 0; i < size; i++) {\n let pair = tree.elements[i];\n if (dataEqual(pair[0], key)) {\n throw new Error(\"Unexpected existed key in assoc\");\n }\n }\n let newPairs = new Array(tree.elements.length + 1);\n for (let idx = 0; idx < size; idx++) {\n let pair = tree.elements[idx];\n newPairs[idx] = pair;\n }\n newPairs[tree.elements.length] = [key, item];\n let result = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: tree.hash,\n elements: newPairs,\n };\n return result;\n }\n }\n else {\n if (thisHash < tree.minHash) {\n if (tree.right == null) {\n let childBranch = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: thisHash,\n elements: [[key, item]],\n };\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: thisHash,\n left: childBranch,\n middle: tree.left,\n right: tree.middle,\n depth: 0, // TODO\n };\n return result;\n }\n else {\n let childBranch = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: thisHash,\n elements: [[key, item]],\n };\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: thisHash,\n left: childBranch,\n middle: tree,\n right: emptyBranch,\n depth: 0, // TODO\n };\n return result;\n }\n }\n if (thisHash > tree.maxHash) {\n // in compact layout, left arm must be existed\n if (tree.middle == null) {\n let childBranch = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: thisHash,\n elements: [[key, item]],\n };\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: thisHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: childBranch,\n right: emptyBranch,\n depth: 0, // TODO\n };\n return result;\n }\n else if (tree.right == null) {\n let childBranch = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: thisHash,\n elements: [[key, item]],\n };\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: thisHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: tree.middle,\n right: childBranch,\n depth: 0, // TODO\n };\n return result;\n }\n else {\n let childBranch = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: thisHash,\n elements: [[key, item]],\n };\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: thisHash,\n minHash: tree.minHash,\n left: tree,\n middle: childBranch,\n right: emptyBranch,\n depth: 0, // TODO\n };\n return result;\n }\n }\n if (rangeContainsHash(tree.left, thisHash)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: assocNew(tree.left, key, item, thisHash),\n middle: tree.middle,\n right: tree.right,\n depth: 0, // TODO\n };\n return result;\n }\n if (rangeContainsHash(tree.middle, thisHash)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: assocNew(tree.middle, key, item, thisHash),\n right: tree.right,\n depth: 0, // TODO\n };\n return result;\n }\n if (rangeContainsHash(tree.right, thisHash)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: tree.middle,\n right: assocNew(tree.right, key, item, thisHash),\n depth: 0, // TODO\n };\n return result;\n }\n if (tree.middle == null) {\n throw new Error(\"unreachable. if inside range, then middle should be here\");\n }\n if (thisHash < getMin(tree.middle)) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: assocNew(tree.left, key, item, thisHash),\n middle: tree.middle,\n right: tree.right,\n depth: 0, // TODO\n };\n return result;\n }\n else {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: tree.middle,\n right: assocNew(tree.right, key, item, thisHash),\n depth: 0, // TODO\n };\n return result;\n }\n }\n}\nexport function assocMap(tree, key, item, disableBalancing = false) {\n if (tree == null || isMapEmpty(tree)) {\n return createLeaf(key, item);\n }\n if (contains(tree, key)) {\n return assocExisted(tree, key, item);\n }\n else {\n return assocNew(tree, key, item);\n }\n}\nfunction dissocExisted(tree, key) {\n if (tree == null) {\n throw new Error(\"Unexpected missing key in dissoc\");\n }\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (tree.hash === hashGenerator(key)) {\n let size = tree.elements.length;\n if (size === 1 && dataEqual(key, tree.elements[0][0])) {\n return emptyBranch;\n }\n else {\n let newPairs = [];\n for (let i = 0; i < size; i++) {\n let pair = tree.elements[i];\n if (!dataEqual(pair[0], key)) {\n newPairs.push(pair);\n }\n }\n let result = { kind: TernaryTreeKind.ternaryTreeLeaf, hash: tree.hash, elements: newPairs };\n return result;\n }\n }\n else {\n throw new Error(\"Unexpected missing key in dissoc on leaf\");\n }\n }\n if (mapLenBound(tree, 2) === 1) {\n if (!contains(tree, key)) {\n throw new Error(\"Unexpected missing key in dissoc single branch\");\n }\n return emptyBranch;\n }\n let thisHash = hashGenerator(key);\n if (rangeContainsHash(tree.left, thisHash)) {\n let changedBranch = dissocExisted(tree.left, key);\n if (isMapEmpty(changedBranch)) {\n if (isMapEmpty(tree.right)) {\n return tree.middle;\n }\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: getMin(tree.middle),\n left: tree.middle,\n middle: tree.right,\n right: emptyBranch,\n depth: 0, // TODO\n };\n return result;\n }\n else {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: getMin(changedBranch),\n left: changedBranch,\n middle: tree.middle,\n right: tree.right,\n depth: 0, // TODO\n };\n return result;\n }\n }\n if (rangeContainsHash(tree.middle, thisHash)) {\n let changedBranch = dissocExisted(tree.middle, key);\n if (isMapEmpty(changedBranch)) {\n if (isMapEmpty(tree.right)) {\n return tree.left;\n }\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: tree.right,\n right: emptyBranch,\n depth: 0, // TODO\n };\n return result;\n }\n else {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: tree.maxHash,\n minHash: tree.minHash,\n left: tree.left,\n middle: changedBranch,\n right: tree.right,\n depth: 0, // TODO\n };\n return result;\n }\n }\n if (rangeContainsHash(tree.right, thisHash)) {\n let changedBranch = dissocExisted(tree.right, key);\n if (changedBranch == null) {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: getMax(tree.middle),\n minHash: tree.minHash,\n left: tree.left,\n middle: tree.middle,\n right: emptyBranch,\n depth: 0, // TODO\n };\n return result;\n }\n else {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n maxHash: getMax(changedBranch),\n minHash: tree.minHash,\n left: tree.left,\n middle: tree.middle,\n right: changedBranch,\n depth: 0, // TODO\n };\n return result;\n }\n }\n throw new Error(\"Cannot find branch in dissoc\");\n}\nexport function dissocMap(tree, key) {\n if (contains(tree, key)) {\n return dissocExisted(tree, key);\n }\n else {\n return tree;\n }\n}\nfunction collectToPairsArray(acc, tree) {\n if (tree != null) {\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n for (let i = 0; i < tree.elements.length; i++) {\n let pair = tree.elements[i];\n acc.push(pair);\n }\n }\n else {\n if (tree.left != null) {\n collectToPairsArray(acc, tree.left);\n }\n if (tree.middle != null) {\n collectToPairsArray(acc, tree.middle);\n }\n if (tree.right != null) {\n collectToPairsArray(acc, tree.right);\n }\n }\n }\n}\n/** similar to `toPairs`, but using Array.push directly */\nexport function toPairsArray(tree) {\n let result = [];\n collectToPairsArray(result, tree);\n return result;\n}\nexport function* toPairs(tree) {\n if (tree != null) {\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n for (let pair of tree.elements) {\n yield pair;\n }\n }\n else {\n if (tree.left != null) {\n for (let item of toPairs(tree.left)) {\n yield item;\n }\n }\n if (tree.middle != null) {\n for (let item of toPairs(tree.middle)) {\n yield item;\n }\n }\n if (tree.right != null) {\n for (let item of toPairs(tree.right)) {\n yield item;\n }\n }\n }\n }\n}\nexport function* toKeys(tree) {\n if (tree != null) {\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n for (let i = 0; i < tree.elements.length; i++) {\n let pair = tree.elements[i];\n yield pair[0];\n }\n }\n else {\n if (tree.left != null) {\n for (let item of toKeys(tree.left)) {\n yield item;\n }\n }\n if (tree.middle != null) {\n for (let item of toKeys(tree.middle)) {\n yield item;\n }\n }\n if (tree.right != null) {\n for (let item of toKeys(tree.right)) {\n yield item;\n }\n }\n }\n }\n}\nexport function* toValues(tree) {\n if (tree != null) {\n if (tree.kind === TernaryTreeKind.ternaryTreeLeaf) {\n for (let i = 0; i < tree.elements.length; i++) {\n let pair = tree.elements[i];\n yield pair[1];\n }\n }\n else {\n if (tree.left != null) {\n for (let item of toValues(tree.left)) {\n yield item;\n }\n }\n if (tree.middle != null) {\n for (let item of toValues(tree.middle)) {\n yield item;\n }\n }\n if (tree.right != null) {\n for (let item of toValues(tree.right)) {\n yield item;\n }\n }\n }\n }\n}\nexport function mapEqual(xs, ys) {\n if (xs === ys) {\n return true;\n }\n if (mapLen(xs) !== mapLen(ys)) {\n return false;\n }\n if (isMapEmpty(xs)) {\n return true;\n }\n for (let pair of toPairsArray(xs)) {\n let key = pair[0];\n let vx = pair[1];\n if (!contains(ys, key)) {\n return false;\n }\n let vy = mapGetDefault(ys, key, null);\n // TODO compare deep structures\n if (!dataEqual(vx, vy)) {\n return false;\n }\n }\n return true;\n}\nexport function merge(xs, ys) {\n let ret = xs;\n let counted = 0;\n for (let [key, item] of toPairs(ys)) {\n ret = assocMap(ret, key, item);\n // # TODO pickd loop by experience\n if (counted > 700) {\n forceMapInplaceBalancing(ret);\n counted = 0;\n }\n else {\n counted = counted + 1;\n }\n }\n return ret;\n}\n// # skip a value, mostly for nil\nexport function mergeSkip(xs, ys, skipped) {\n let ret = xs;\n let counted = 0;\n for (let [key, item] of toPairs(ys)) {\n if (dataEqual(item, skipped)) {\n continue;\n }\n ret = assocMap(ret, key, item);\n // # TODO pickd loop by experience\n if (counted > 700) {\n forceMapInplaceBalancing(ret);\n counted = 0;\n }\n else {\n counted = counted + 1;\n }\n }\n return ret;\n}\n// this function mutates original tree to make it more balanced\nexport function forceMapInplaceBalancing(tree) {\n // echo \"Force inplace balancing of list\"\n if (tree.kind === TernaryTreeKind.ternaryTreeBranch) {\n let xs = toOrderedHashEntries(tree);\n let newTree = makeTernaryTreeMap(xs.length, 0, xs);\n tree.left = newTree.left;\n tree.middle = newTree.middle;\n tree.right = newTree.right;\n }\n else {\n // discard\n }\n}\nexport function sameMapShape(xs, ys) {\n if (xs == null) {\n if (ys == null) {\n return true;\n }\n else {\n return false;\n }\n }\n if (ys == null) {\n return false;\n }\n if (mapLen(xs) !== mapLen(ys)) {\n return false;\n }\n if (xs.kind !== ys.kind) {\n return false;\n }\n if (xs.kind === TernaryTreeKind.ternaryTreeLeaf && ys.kind === TernaryTreeKind.ternaryTreeLeaf) {\n if (xs.elements.length !== ys.elements.length) {\n return false;\n }\n for (let idx = 0; idx < xs.elements.length; idx++) {\n if (!dataEqual(xs.elements[idx], ys.elements[idx])) {\n return false;\n }\n }\n return true;\n }\n else if (xs.kind === TernaryTreeKind.ternaryTreeBranch && ys.kind === TernaryTreeKind.ternaryTreeBranch) {\n if (!sameMapShape(xs.left, ys.left)) {\n return false;\n }\n if (!sameMapShape(xs.middle, ys.middle)) {\n return false;\n }\n if (!sameMapShape(xs.right, ys.right)) {\n return false;\n }\n return true;\n }\n else {\n throw new Error(\"Unknown\");\n }\n}\nexport function mapMapValues(tree, f) {\n if (tree == null) {\n return tree;\n }\n switch (tree.kind) {\n case TernaryTreeKind.ternaryTreeLeaf: {\n let newElements = new Array(tree.elements.length);\n let size = tree.elements.length;\n for (let idx = 0; idx < size; idx++) {\n newElements[idx] = [tree.elements[idx][0], f(tree.elements[idx][1])];\n }\n let result = {\n kind: TernaryTreeKind.ternaryTreeLeaf,\n hash: tree.hash,\n elements: newElements,\n };\n return result;\n }\n case TernaryTreeKind.ternaryTreeBranch: {\n let result = {\n kind: TernaryTreeKind.ternaryTreeBranch,\n depth: tree.depth,\n minHash: tree.minHash,\n maxHash: tree.maxHash,\n left: mapMapValues(tree.left, f),\n middle: mapMapValues(tree.middle, f),\n right: mapMapValues(tree.right, f),\n };\n return result;\n }\n }\n}\n","import { listToString, initTernaryTreeList, initTernaryTreeListFromRange, indexOf, findIndex, reverse, checkListStructure, slice, listToPairs, listToItems, formatListInline, sameListShape, assocBefore, concat, assocAfter, prepend, append, rest, butlast, first, assocList, dissocList, listGet, insert, initEmptyTernaryTreeList, last, listLen, forceListInplaceBalancing, listEqual, indexToItems, listMapValues, } from \"./list\";\nimport { test, check, arrayEqual, checkEqual } from \"./utils\";\nexport let runListTests = () => {\n test(\"init list\", () => {\n check(listToString(initTernaryTreeList([1, 2, 3, 4])) === \"TernaryTreeList[4, ...]\");\n let origin11 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];\n let data11 = initTernaryTreeList(origin11);\n check(checkListStructure(data11));\n checkEqual(formatListInline(data11), \"((1 (2 3 _) 4) (5 6 7) (8 (9 10 _) 11))\");\n check(arrayEqual(origin11, [...listToItems(data11)]));\n check(arrayEqual([...listToItems(data11)], [...indexToItems(data11)]));\n let emptyXs = new Array(0);\n check(listEqual(initEmptyTernaryTreeList(), initTernaryTreeList(emptyXs)));\n });\n test(\"list operations\", () => {\n let origin11 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];\n let data11 = initTernaryTreeList(origin11);\n // get\n for (let idx = 0; idx < origin11.length; idx++) {\n check(origin11[idx] === listGet(data11, idx));\n }\n check(first(data11) === 1);\n check(last(data11) === 11);\n // assoc\n let origin5 = [1, 2, 3, 4, 5];\n let data5 = initTernaryTreeList(origin5);\n let updated = assocList(data5, 3, 10);\n check(listGet(updated, 3) === 10);\n check(listGet(data5, 3) === 4);\n check(listLen(updated) === listLen(data5));\n for (let idx = 0; idx < listLen(data5); idx++) {\n // echo data5.dissoc(idx).formatInline\n check(listLen(dissocList(data5, idx)) === listLen(data5) - 1);\n }\n checkEqual(formatListInline(data5), \"((1 2 _) 3 (4 5 _))\");\n checkEqual(formatListInline(dissocList(data5, 0)), \"(2 3 (4 5 _))\");\n checkEqual(formatListInline(dissocList(data5, 1)), \"(1 3 (4 5 _))\");\n checkEqual(formatListInline(dissocList(data5, 2)), \"((1 2 _) (4 5 _) _)\");\n checkEqual(formatListInline(dissocList(data5, 3)), \"((1 2 _) 3 5)\");\n checkEqual(formatListInline(dissocList(data5, 4)), \"((1 2 _) 3 4)\");\n checkEqual(formatListInline(rest(initTernaryTreeList([1]))), \"_\");\n checkEqual(formatListInline(rest(initTernaryTreeList([1, 2]))), \"2\");\n checkEqual(formatListInline(rest(initTernaryTreeList([1, 2, 3]))), \"(2 3 _)\");\n checkEqual(formatListInline(rest(initTernaryTreeList([1, 2, 3, 4]))), \"((2 3 _) 4 _)\");\n checkEqual(formatListInline(rest(initTernaryTreeList([1, 2, 3, 4, 5]))), \"(2 3 (4 5 _))\");\n checkEqual(formatListInline(butlast(initTernaryTreeList([1]))), \"_\");\n checkEqual(formatListInline(butlast(initTernaryTreeList([1, 2]))), \"1\");\n checkEqual(formatListInline(butlast(initTernaryTreeList([1, 2, 3]))), \"(1 2 _)\");\n checkEqual(formatListInline(butlast(initTernaryTreeList([1, 2, 3, 4]))), \"(1 (2 3 _) _)\");\n checkEqual(formatListInline(butlast(initTernaryTreeList([1, 2, 3, 4, 5]))), \"((1 2 _) 3 4)\");\n });\n test(\"list insertions\", () => {\n let origin5 = [1, 2, 3, 4, 5];\n let data5 = initTernaryTreeList(origin5);\n checkEqual(formatListInline(data5), \"((1 2 _) 3 (4 5 _))\");\n checkEqual(formatListInline(insert(data5, 0, 10, false)), \"(10 ((1 2 _) 3 (4 5 _)) _)\");\n checkEqual(formatListInline(insert(data5, 0, 10, true)), \"((1 10 2) 3 (4 5 _))\");\n checkEqual(formatListInline(insert(data5, 1, 10, false)), \"((1 10 2) 3 (4 5 _))\");\n checkEqual(formatListInline(insert(data5, 1, 10, true)), \"((1 2 10) 3 (4 5 _))\");\n checkEqual(formatListInline(insert(data5, 2, 10, false)), \"((1 2 _) (10 3 _) (4 5 _))\");\n checkEqual(formatListInline(insert(data5, 2, 10, true)), \"((1 2 _) (3 10 _) (4 5 _))\");\n checkEqual(formatListInline(insert(data5, 3, 10, false)), \"((1 2 _) 3 (10 4 5))\");\n checkEqual(formatListInline(insert(data5, 3, 10, true)), \"((1 2 _) 3 (4 10 5))\");\n checkEqual(formatListInline(insert(data5, 4, 10, false)), \"((1 2 _) 3 (4 10 5))\");\n checkEqual(formatListInline(insert(data5, 4, 10, true)), \"(((1 2 _) 3 (4 5 _)) 10 _)\");\n let origin4 = [1, 2, 3, 4];\n let data4 = initTernaryTreeList(origin4);\n checkEqual(formatListInline(assocBefore(data4, 3, 10)), \"(1 (2 3 _) (10 4 _))\");\n checkEqual(formatListInline(assocAfter(data4, 3, 10)), \"(1 (2 3 _) (4 10 _))\");\n checkEqual(formatListInline(prepend(data4, 10)), \"((10 1 _) (2 3 _) 4)\");\n checkEqual(formatListInline(append(data4, 10)), \"(1 (2 3 _) (4 10 _))\");\n });\n test(\"concat\", () => {\n let data1 = initTernaryTreeList([1, 2]);\n let data2 = initTernaryTreeList([3, 4]);\n let data3 = initTernaryTreeList([5, 6]);\n let data4 = initTernaryTreeList([7, 8]);\n check(formatListInline(concat(data1, data2)) === \"((1 2 _) (3 4 _) _)\");\n check(formatListInline(concat(initTernaryTreeList([]), data1)) === \"(1 2 _)\");\n check(formatListInline(concat(data1, data2, data3)) === \"((1 2 _) (3 4 _) (5 6 _))\");\n check(formatListInline(concat(data1, data2, data3, data4)) === \"((1 2 _) ((3 4 _) (5 6 _) _) (7 8 _))\");\n checkListStructure(concat(data1, data2));\n checkListStructure(concat(data1, data2, data3));\n checkListStructure(concat(data1, data2, data3, data4));\n check(listLen(concat(data1, data2, data3, data4)) === 8);\n });\n test(\"check(equality\", () => {\n let origin4 = [1, 2, 3, 4];\n let data4 = initTernaryTreeList(origin4);\n let data4n = initTernaryTreeList(origin4);\n let data4Made = prepend(initTernaryTreeList([2, 3, 4]), 1);\n check(sameListShape(data4, data4) === true);\n check(sameListShape(data4, data4n) === true);\n check(sameListShape(data4, data4Made) === false);\n check(listEqual(data4, data4n));\n check(listEqual(data4, data4Made));\n check(listEqual(data4n, data4Made));\n check(data4 !== data4Made); // identical false\n });\n test(\"force balancing\", () => {\n var data = initTernaryTreeList([]);\n for (let idx = 0; idx < 20; idx++) {\n data = append(data, idx, true);\n }\n // echo data.formatInline\n check(formatListInline(data) === \"(((0 1 2) (3 4 5) (6 7 8)) ((9 10 11) (12 13 14) (15 16 17)) (18 19 _))\");\n forceListInplaceBalancing(data);\n check(formatListInline(data) === \"(((0 1 _) (2 3 4) (5 6 _)) ((7 8 _) (9 10 _) (11 12 _)) ((13 14 _) (15 16 17) (18 19 _)))\");\n // echo data.formatInline\n });\n test(\"iterator\", () => {\n let origin4 = [1, 2, 3, 4];\n let data4 = initTernaryTreeList(origin4);\n var i = 0;\n for (let item of listToItems(data4)) {\n i = i + 1;\n }\n check(i === 4);\n i = 0;\n for (let [idx, item] of listToPairs(data4)) {\n i = i + idx;\n }\n check(i === 6);\n });\n test(\"check structure\", () => {\n var data = initTernaryTreeList([]);\n for (let idx = 0; idx < 20; idx++) {\n data = append(data, idx, true);\n }\n check(checkListStructure(data));\n let origin11 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];\n let data11 = initTernaryTreeList(origin11);\n check(checkListStructure(data11));\n });\n test(\"slices\", () => {\n var data = initTernaryTreeList([]);\n for (let idx = 0; idx < 40; idx++) {\n data = append(data, idx, true);\n }\n var list40 = [];\n for (let idx = 0; idx < 40; idx++) {\n list40.push(idx);\n }\n for (let i = 0; i < 40; i++) {\n for (let j = i; j < 40; j++) {\n check(arrayEqual([...listToItems(slice(data, i, j))], list40.slice(i, j)));\n }\n }\n });\n test(\"reverse\", () => {\n let data = initTernaryTreeList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);\n let reversedData = reverse(data);\n check(arrayEqual([...listToItems(data)].reverse(), [...listToItems(reversedData)]));\n check(checkListStructure(reversedData));\n });\n test(\"list traverse\", () => {\n var i = 0;\n let data = initTernaryTreeList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);\n for (let x of listToItems(data)) {\n i = i + 1;\n }\n check(i === 10);\n });\n test(\"index of\", () => {\n let data = initTernaryTreeList([1, 2, 3, 4, 5, 6, 7, 8]);\n check(indexOf(data, 2) === 1);\n check(findIndex(data, (x) => x === 2) === 1);\n check(indexOf(data, 9) === -1);\n check(findIndex(data, (x) => x === 9) === -1);\n });\n test(\"map values\", () => {\n let data = initTernaryTreeList([1, 2, 3, 4]);\n let data2 = initTernaryTreeList([1, 4, 9, 16]);\n let data3 = listMapValues(data, (x) => x * x);\n checkListStructure(data3);\n check(listEqual(data2, data3));\n check(formatListInline(data2) === formatListInline(data3));\n });\n test(\"concat\", () => {\n let data1 = initTernaryTreeList([3, 4]);\n let data2 = initTernaryTreeListFromRange([1, 2, 3, 4, 5, 6], 2, 4);\n check(listEqual(data1, data2));\n });\n};\n","import { hashGenerator } from \"./types\";\nimport { test, check, cmp, deepEqual, justDisplay } from \"./utils\";\nimport { initTernaryTreeMap, initTernaryTreeMapFromArray, toHashSortedPairs, merge, mergeSkip, formatMapInline, assocMap, dissocMap, contains, toPairs, initEmptyTernaryTreeMap, sameMapShape, checkMapStructure, mapLen, mapEqual, toKeys, toPairsArray, mapMapValues, mapGetDefault, } from \"./map\";\nexport let runMapTests = () => {\n test(\"init map\", () => {\n var dict = new Map();\n var inList = [];\n for (let idx = 0; idx < 10; idx++) {\n dict.set(`${idx}`, idx + 10);\n inList.push([`${idx}`, idx + 10]);\n }\n // TODO\n inList.sort((x, y) => {\n let hx = hashGenerator(x[0]);\n let hy = hashGenerator(y[0]);\n return cmp(hx, hy);\n });\n let data10 = initTernaryTreeMap(dict);\n let data11 = initTernaryTreeMapFromArray(inList);\n checkMapStructure(data10);\n checkMapStructure(data11);\n // echo data10\n justDisplay(formatMapInline(data10, true), \" ((0:10 1:11 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19))\");\n check(deepEqual(toHashSortedPairs(data10), inList));\n check(deepEqual(toHashSortedPairs(data11), inList));\n check(contains(data10, \"1\") === true);\n check(contains(data10, \"11\") === false);\n check(deepEqual(mapGetDefault(data10, \"1\", null), 11));\n check(deepEqual(mapGetDefault(data10, \"111\", 0), 0));\n // check(deepEqual(mapGetDefault(data10, \"11\", {} as any), null)); // should throws error\n let emptyData = new Map();\n check(mapEqual(initEmptyTernaryTreeMap(), initTernaryTreeMap(emptyData)));\n });\n test(\"assoc and contains\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 100; idx++) {\n dict.set(`${idx * 2}`, idx);\n }\n let data = initTernaryTreeMap(dict);\n for (let idx = 0; idx < 100; idx++) {\n dict.set(`${idx * 2 + 1}`, idx);\n let data2 = assocMap(data, `${idx * 2 + 1}`, idx);\n check(contains(data2, `${idx * 2 + 1}`));\n }\n var dict = new Map();\n data = initTernaryTreeMap(dict);\n for (let idx = 0; idx < 1000; idx++) {\n let p = 100 - idx / 10;\n data = assocMap(data, `${p}`, idx);\n check(contains(data, `${p}`));\n }\n });\n test(\"check structure\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 100; idx++) {\n dict.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n check(checkMapStructure(data));\n });\n test(\"assoc map\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 10; idx++) {\n dict.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n // echo data.formatInline\n check(contains(data, \"1\") === true);\n check(contains(data, \"12\") === false);\n checkMapStructure(data);\n justDisplay(formatMapInline(assocMap(data, \"1\", 2222), true), \"((0:10 1:2222 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19))\");\n justDisplay(formatMapInline(assocMap(data, \"23\", 2222), true), \"(((0:10 1:11 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19)) 23:2222 _)\");\n });\n test(\"dissoc\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 10; idx++) {\n dict.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n checkMapStructure(data);\n // echo data.formatInline\n for (let idx = 0; idx < 10; idx++) {\n let v = dissocMap(data, `${idx}`);\n check(contains(v, `${idx}`) === false);\n check(contains(data, `${idx}`) === true);\n check(mapLen(v) === mapLen(data) - 1);\n }\n for (let idx = 10; idx < 12; idx++) {\n let v = dissocMap(data, `${idx}`);\n check(contains(v, `${idx}`) === false);\n check(mapLen(v) === mapLen(data));\n }\n });\n test(\"to array\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 10; idx++) {\n dict.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n checkMapStructure(data);\n // TODO\n // justDisplay((mapToString(toPairs(data))) , \"@[2:12, 3:13, 7:17, 9:19, 6:16, 5:15, 1:11, 8:18, 0:10, 4:14]\")\n justDisplay([...toKeys(data)], [\"2\", \"3\", \"7\", \"9\", \"6\", \"5\", \"1\", \"8\", \"0\", \"4\"]);\n check(deepEqual(toPairsArray(data), [...toPairs(data)]));\n });\n test(\"Equality\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 10; idx++) {\n dict.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n let b = dissocMap(data, \"3\");\n checkMapStructure(data);\n checkMapStructure(b);\n check(mapEqual(data, data));\n check(!mapEqual(data, b));\n let c = assocMap(data, \"3\", 15);\n check(sameMapShape(data, data));\n check(sameMapShape(data, b) === false);\n check(sameMapShape(data, c) === false);\n let d = assocMap(c, \"3\", 13);\n check(mapEqual(data, d));\n check(data !== d); // not identical\n });\n test(\"Merge\", () => {\n var dict = new Map();\n var dictBoth = new Map();\n for (let idx = 0; idx < 4; idx++) {\n dict.set(`${idx}`, idx + 10);\n dictBoth.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n checkMapStructure(data);\n var dictB = new Map();\n for (let idx = 10; idx < 14; idx++) {\n dictB.set(`${idx}`, idx + 23);\n dictBoth.set(`${idx}`, idx + 23);\n }\n let b = initTernaryTreeMap(dictB);\n let merged = merge(data, b);\n let both = initTernaryTreeMap(dictBoth);\n check(mapEqual(merged, both));\n });\n test(\"Merge skip\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 4; idx++) {\n dict.set(`${idx}`, idx + 10);\n }\n let a = initTernaryTreeMap(dict);\n checkMapStructure(a);\n var dict2 = new Map();\n for (let idx = 0; idx < 4; idx++) {\n dict2.set(`${idx}`, idx + 11);\n }\n let b = initTernaryTreeMap(dict2);\n checkMapStructure(b);\n let c = mergeSkip(a, b, 11);\n check(deepEqual(mapGetDefault(c, \"0\", null), 10));\n check(deepEqual(mapGetDefault(c, \"1\", null), 12));\n check(deepEqual(mapGetDefault(c, \"2\", null), 13));\n check(deepEqual(mapGetDefault(c, \"3\", null), 14));\n });\n test(\"iterator\", () => {\n var dict = new Map();\n var dictBoth = new Map();\n for (let idx = 0; idx < 4; idx++) {\n dict.set(`${idx}`, idx + 10);\n dictBoth.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n checkMapStructure(data);\n var i = 0;\n for (let [k, v] of toPairs(data)) {\n i = i + 1;\n }\n check(i === 4);\n i = 0;\n for (let key of toPairs(data)) {\n i = i + 1;\n }\n check(i === 4);\n });\n test(\"each map\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 100; idx++) {\n dict.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n checkMapStructure(data);\n var i = 0;\n for (let [k, v] of toPairs(data)) {\n // echo \"..{k}-{v}..\"\n i = i + 1;\n }\n check(i === 100);\n });\n test(\"map values\", () => {\n var dict = new Map();\n for (let idx = 0; idx < 4; idx++) {\n dict.set(`${idx}`, idx + 10);\n }\n let data = initTernaryTreeMap(dict);\n var dict2 = new Map();\n for (let idx = 0; idx < 4; idx++) {\n dict2.set(`${idx}`, idx + 20);\n }\n let data2 = initTernaryTreeMap(dict2);\n let data3 = mapMapValues(data, (x) => x + 10);\n checkMapStructure(data3);\n checkMapStructure(data3);\n check(mapEqual(data2, data3));\n check(formatMapInline(data2) === formatMapInline(data3));\n });\n};\n","export var TernaryTreeKind;\n(function (TernaryTreeKind) {\n TernaryTreeKind[TernaryTreeKind[\"ternaryTreeBranch\"] = 0] = \"ternaryTreeBranch\";\n TernaryTreeKind[TernaryTreeKind[\"ternaryTreeLeaf\"] = 1] = \"ternaryTreeLeaf\";\n})(TernaryTreeKind || (TernaryTreeKind = {}));\nexport let valueHash = (x) => {\n if (typeof x === \"number\") {\n // console.log(\"hash for x:\", x, \"\\t\", result);\n return x;\n }\n else if (typeof x === \"string\") {\n let h = 0;\n // https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0#gistcomment-2775538\n for (var i = 0; i < x.length; i++) {\n h = Math.imul(31, h) + (x[i].charCodeAt(0) | 0);\n }\n // console.log(\"hash for x:\", x, \"\\t\", result);\n return h;\n }\n throw new Error(\"Hash solution not provided for this type(other than number and string)\");\n};\n/** default hash function only handles number and string, need customization */\nexport let hashGenerator = valueHash;\n/** allow customizing hash function from outside */\nexport let overwriteHashGenerator = (f) => {\n hashGenerator = f;\n};\nexport let mergeValueHash = (base, x) => {\n if (typeof x === \"number\") {\n return Math.imul(31, base) + x;\n }\n else if (typeof x === \"string\") {\n let h = base;\n // https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0#gistcomment-2775538\n for (var i = 0; i < x.length; i++) {\n h = Math.imul(31, h) + (x[i].charCodeAt(0) | 0);\n }\n return h;\n }\n throw new Error(\"Hash solution not provided for this type(other than number and string)\");\n};\n","/** by default, it compares by reference\n * supposed to be overwritten by user\n */\nexport let dataEqual = (x, y) => {\n return x === y;\n};\nexport let overwriteComparator = (f) => {\n dataEqual = f;\n};\nexport let roughIntPow = (x, times) => {\n if (times < 1) {\n return x;\n }\n let result = 1;\n for (let idx = 0; idx < times; idx++) {\n result = result * x;\n }\n return result;\n};\nexport let divideTernarySizes = (size) => {\n if (size < 0) {\n throw new Error(\"Unexpected negative size\");\n }\n let extra = size % 3;\n let groupSize = Math.floor(size / 3);\n var leftSize = groupSize;\n var middleSize = groupSize;\n var rightSize = groupSize;\n switch (extra) {\n case 0:\n break;\n case 1:\n middleSize = middleSize + 1;\n break;\n case 2:\n leftSize = leftSize + 1;\n rightSize = rightSize + 1;\n break;\n default:\n throw new Error(`Unexpected mod result ${extra}`);\n }\n return { left: leftSize, middle: middleSize, right: rightSize };\n};\nexport function shallowCloneArray(xs) {\n let ys = new Array(xs.length);\n for (let i = 0; i < xs.length; i++) {\n ys[i] = xs[i];\n }\n return ys;\n}\nexport let test = (name, cb) => {\n console.log(\"Test:\", name);\n cb();\n};\nexport let check = (x) => {\n if (!x) {\n throw new Error(\"Test failed\");\n }\n};\n/** compare by reference */\nexport let checkEqual = (x, y) => {\n if (x !== y) {\n console.log(\"Left: \", x);\n console.log(\"Right: \", y);\n throw new Error(\"Test failed\");\n }\n};\nexport let justDisplay = (x, y) => {\n console.group(\"Compare:\");\n console.log(x);\n console.log(y);\n console.groupEnd();\n};\nexport let cmp = (x, y) => {\n if (x < y) {\n return -1;\n }\n if (x > y) {\n return 1;\n }\n return 0;\n};\n// https://stackoverflow.com/a/25456134/883571\nexport let deepEqual = function (x, y) {\n if (x === y) {\n return true;\n }\n else if (typeof x === \"object\" && x != null && typeof y === \"object\" && y != null) {\n if (Object.keys(x).length != Object.keys(y).length)\n return false;\n for (var prop in x) {\n if (y.hasOwnProperty(prop)) {\n if (!deepEqual(x[prop], y[prop]))\n return false;\n }\n else\n return false;\n }\n return true;\n }\n else\n return false;\n};\nexport let arrayEqual = (xs, ys) => {\n if (xs.length != ys.length) {\n return false;\n }\n for (let idx = 0; idx < xs.length; idx++) {\n if (xs[idx] !== ys[idx]) {\n return false;\n }\n }\n return true;\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { deepEqual, overwriteComparator } from \"./utils\";\nimport \"./test-list\";\nimport \"./test-map\";\nimport { runListTests } from \"./test-list\";\nimport { runMapTests } from \"./test-map\";\nimport { mergeValueHash, overwriteHashGenerator, valueHash } from \"./types\";\noverwriteComparator((x, y) => {\n // console.log(\"comparing\", x, y);\n return deepEqual(x, y);\n});\noverwriteHashGenerator((x) => {\n let ret = mergeValueHash(10, valueHash(x));\n // console.log(\"hashing\", x, ret);\n return ret;\n});\nrunListTests();\nrunMapTests();\n"],"names":[],"sourceRoot":""}
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
package/lib/main.d.ts
DELETED
package/src/costs.nim
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# TODO get a ts version
|
2
|
-
|
3
|
-
import nimprof
|
4
|
-
import tables
|
5
|
-
import strformat
|
6
|
-
import algorithm
|
7
|
-
import hashes
|
8
|
-
import times
|
9
|
-
|
10
|
-
import ternary_tree
|
11
|
-
|
12
|
-
let n = 2000
|
13
|
-
|
14
|
-
proc testList(): void =
|
15
|
-
var data = initTernaryTreeList[int](@[])
|
16
|
-
for idx in 0..<n:
|
17
|
-
data = data.append(idx)
|
18
|
-
|
19
|
-
for y in 0..<100:
|
20
|
-
for idx in 0..<n:
|
21
|
-
discard data[idx]
|
22
|
-
|
23
|
-
for item in data:
|
24
|
-
discard item
|
25
|
-
|
26
|
-
proc testMap(): void =
|
27
|
-
var dict: Table[string, int]
|
28
|
-
var data10 = initTernaryTreeMap[string, int](dict)
|
29
|
-
|
30
|
-
for idx in 0..<n:
|
31
|
-
data10 = data10.assoc($idx, idx + 10)
|
32
|
-
|
33
|
-
for y in 0..<40:
|
34
|
-
for idx in 0..<n:
|
35
|
-
discard data10[$idx]
|
36
|
-
|
37
|
-
echo data10.getDepth
|
38
|
-
data10.forceInplaceBalancing
|
39
|
-
echo data10.getDepth
|
40
|
-
|
41
|
-
proc testMapMerge(): void =
|
42
|
-
var dict: Table[string, int]
|
43
|
-
var data10 = initTernaryTreeMap[string, int](dict)
|
44
|
-
var data11 = initTernaryTreeMap[string, int](dict)
|
45
|
-
|
46
|
-
for idx in 0..<n:
|
47
|
-
data10 = data10.assoc($idx, idx + 10)
|
48
|
-
|
49
|
-
for idx in 0..<n:
|
50
|
-
data11 = data10.assoc( "x" & $idx, idx + 11)
|
51
|
-
|
52
|
-
for y in 0..<20:
|
53
|
-
discard data10.merge(data11)
|
54
|
-
|
55
|
-
let t1 = now()
|
56
|
-
|
57
|
-
testMap()
|
58
|
-
# testList()
|
59
|
-
# testMapMerge()
|
60
|
-
|
61
|
-
let t2 = now()
|
62
|
-
echo "Costs: ", t2 - t1
|
package/src/hash.ts
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
export type Hash = number;
|
2
|
-
|
3
|
-
// https://2ality.com/2012/02/js-integers.html
|
4
|
-
function modulo(a: number, b: number) {
|
5
|
-
return a - Math.floor(a / b) * b;
|
6
|
-
}
|
7
|
-
function toUint32(x: number) {
|
8
|
-
return modulo(x, Math.pow(2, 32));
|
9
|
-
}
|
10
|
-
|
11
|
-
function toInt32(x: number) {
|
12
|
-
var uint32 = toUint32(x);
|
13
|
-
if (uint32 >= Math.pow(2, 31)) {
|
14
|
-
return uint32 - Math.pow(2, 32);
|
15
|
-
} else {
|
16
|
-
return uint32;
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
// trying Nim code but JavaScript does not has uint, only float
|
21
|
-
// https://github.com/nim-lang/Nim/blob/version-1-4/lib/pure/hashes.nim#L54-L73
|
22
|
-
export let startHash = (h: Hash, val: number): Hash => {
|
23
|
-
// h = toUint32(h);
|
24
|
-
// val = toUint32(val);
|
25
|
-
let res = h + val;
|
26
|
-
res = res + (res << 10);
|
27
|
-
res = res | (res >>> 6);
|
28
|
-
// return toInt32(res);
|
29
|
-
return res;
|
30
|
-
};
|
31
|
-
|
32
|
-
export let finishHash = (h: Hash) => {
|
33
|
-
// h = toUint32(h);
|
34
|
-
let res = h + (h << 3);
|
35
|
-
res = res | (res >>> 11);
|
36
|
-
res = res + (res << 15);
|
37
|
-
// return toInt32(res);
|
38
|
-
return res;
|
39
|
-
};
|
40
|
-
|
41
|
-
// export let valueHash = (x: any): number => {
|
42
|
-
// let result: number = 0;
|
43
|
-
// if (typeof x === "number") {
|
44
|
-
// let h = startHash(0, x);
|
45
|
-
// result = finishHash(h);
|
46
|
-
// } else if (typeof x === "string") {
|
47
|
-
// let h = 0;
|
48
|
-
// for (var i = 0; i < x.length; i++) {
|
49
|
-
// h = startHash(h, x[i].charCodeAt(0));
|
50
|
-
// }
|
51
|
-
// result = finishHash(h);
|
52
|
-
// } else {
|
53
|
-
// throw new Error("Hash solution not provided for this type(other than number and string)");
|
54
|
-
// }
|
55
|
-
// console.log("hash for x:", x, "\t", result);
|
56
|
-
// return result;
|
57
|
-
// };
|
58
|
-
|
59
|
-
// TODO
|
60
|
-
// console.log(valueHash(1));
|
61
|
-
// console.log("a".charCodeAt(0));
|
62
|
-
// console.log(valueHash("a".charCodeAt(0)));
|
63
|
-
// console.log(valueHash("a"));
|
64
|
-
// console.log(valueHash("2"));
|
65
|
-
|
66
|
-
// js outputs
|
67
|
-
// 07143837
|
68
|
-
// 97
|
69
|
-
// -586335745
|
70
|
-
// -586335745
|
71
|
-
// -1837488922
|
72
|
-
|
73
|
-
// Nim outputs
|
74
|
-
// 8641844181895329213
|
75
|
-
// 97
|
76
|
-
// 661948602591176288
|
77
|
-
// 661948602591176288
|
78
|
-
// 19522071
|