@dra2020/baseclient 1.0.51 → 1.0.54

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.
@@ -9251,6 +9251,7 @@ __exportStar(__webpack_require__(/*! ./countedhash */ "./lib/util/countedhash.ts
9251
9251
  __exportStar(__webpack_require__(/*! ./indexedarray */ "./lib/util/indexedarray.ts"), exports);
9252
9252
  __exportStar(__webpack_require__(/*! ./gradient */ "./lib/util/gradient.ts"), exports);
9253
9253
  __exportStar(__webpack_require__(/*! ./bintrie */ "./lib/util/bintrie.ts"), exports);
9254
+ __exportStar(__webpack_require__(/*! ./bitset */ "./lib/util/bitset.ts"), exports);
9254
9255
 
9255
9256
 
9256
9257
  /***/ }),
@@ -9712,6 +9713,101 @@ class BinTrieBuilder {
9712
9713
  exports.BinTrieBuilder = BinTrieBuilder;
9713
9714
 
9714
9715
 
9716
+ /***/ }),
9717
+
9718
+ /***/ "./lib/util/bitset.ts":
9719
+ /*!****************************!*\
9720
+ !*** ./lib/util/bitset.ts ***!
9721
+ \****************************/
9722
+ /***/ ((__unused_webpack_module, exports) => {
9723
+
9724
+
9725
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
9726
+ exports.ListToBitset = void 0;
9727
+ const BitLookup = [1, 2, 4, 8, 16, 32, 64, 128];
9728
+ // In NodeJS:
9729
+ // {
9730
+ // btoa: (s: string) => { return Buffer.from(s, 'binary').toString('base64') },
9731
+ // atob: (s: string) => { return Buffer.from(s, 'base64').toString('binary') },
9732
+ // }
9733
+ // In Browser:
9734
+ // {
9735
+ // btoa: window.btoa,
9736
+ // atob: window.atob,
9737
+ // }
9738
+ class ListToBitset {
9739
+ constructor(list, converter) {
9740
+ this.list = list;
9741
+ this.converter = converter;
9742
+ }
9743
+ toBits(l) {
9744
+ if (!this.index) {
9745
+ this.size = Math.floor((this.list.length + 7) / 8);
9746
+ this.index = {};
9747
+ this.list.forEach((s, i) => { this.index[s] = i; });
9748
+ }
9749
+ let ab = new ArrayBuffer(this.size);
9750
+ let u8 = new Uint8Array(ab);
9751
+ if (l)
9752
+ l.forEach(s => {
9753
+ let n = this.index[s];
9754
+ let i = Math.floor(n / 8);
9755
+ u8[i] |= BitLookup[n % 8];
9756
+ });
9757
+ return u8;
9758
+ }
9759
+ toList(u8) {
9760
+ let list = [];
9761
+ for (let i = 0; i < u8.length; i++) {
9762
+ let u = u8[i];
9763
+ if (u) {
9764
+ if (u & 1)
9765
+ list.push(this.list[i * 8 + 0]);
9766
+ if (u & 2)
9767
+ list.push(this.list[i * 8 + 1]);
9768
+ if (u & 4)
9769
+ list.push(this.list[i * 8 + 2]);
9770
+ if (u & 8)
9771
+ list.push(this.list[i * 8 + 3]);
9772
+ if (u & 16)
9773
+ list.push(this.list[i * 8 + 4]);
9774
+ if (u & 32)
9775
+ list.push(this.list[i * 8 + 5]);
9776
+ if (u & 64)
9777
+ list.push(this.list[i * 8 + 6]);
9778
+ if (u & 128)
9779
+ list.push(this.list[i * 8 + 7]);
9780
+ }
9781
+ }
9782
+ return list;
9783
+ }
9784
+ base64tou8(base64) {
9785
+ let raw = this.converter.atob(base64);
9786
+ let rawLength = raw.length;
9787
+ let u8 = new Uint8Array(new ArrayBuffer(rawLength));
9788
+ for (let i = 0; i < rawLength; i++)
9789
+ u8[i] = raw.charCodeAt(i);
9790
+ return u8;
9791
+ }
9792
+ u8ToBase64(u8) {
9793
+ let binary = [];
9794
+ let len = u8.byteLength;
9795
+ for (let i = 0; i < len; i++) {
9796
+ binary.push(String.fromCharCode(u8[i]));
9797
+ }
9798
+ return this.converter.btoa(binary.join(''));
9799
+ }
9800
+ fromBitString(base64) {
9801
+ return this.toList(this.base64tou8(base64));
9802
+ }
9803
+ toBitString(l) {
9804
+ // Note: On server, Buffer.from(this.toBits(l)).toString('base64') probably faster
9805
+ return this.u8ToBase64(this.toBits(l));
9806
+ }
9807
+ }
9808
+ exports.ListToBitset = ListToBitset;
9809
+
9810
+
9715
9811
  /***/ }),
9716
9812
 
9717
9813
  /***/ "./lib/util/countedhash.ts":