brotli-lib 0.0.1 → 0.0.2
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/README.md +4 -4
- package/dist/encode/backward-references.d.ts.map +1 -1
- package/dist/encode/entropy-encode.d.ts.map +1 -1
- package/dist/encode/hash-binary-tree.d.ts.map +1 -1
- package/dist/encode/hash-chains.d.ts.map +1 -1
- package/dist/encode/match.d.ts +0 -1
- package/dist/encode/match.d.ts.map +1 -1
- package/dist/encode.cjs +118 -77
- package/dist/encode.js +118 -77
- package/dist/index.cjs +118 -77
- package/dist/index.js +118 -77
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,11 +85,11 @@ Encoder vs Node.js native `zlib.brotliCompressSync` (quality 11):
|
|
|
85
85
|
|
|
86
86
|
| Input | brotli-lib | node:zlib |
|
|
87
87
|
|-------|-----------|-----------|
|
|
88
|
-
| 13 B | 0.
|
|
89
|
-
| 4.5 KB | 0.
|
|
90
|
-
| 45 KB |
|
|
88
|
+
| 13 B | 0.0004 ms | 0.22 ms |
|
|
89
|
+
| 4.5 KB | 0.38 ms | 0.43 ms |
|
|
90
|
+
| 45 KB | 3.5 ms | 1.6 ms |
|
|
91
91
|
|
|
92
|
-
Much faster for tiny inputs (no native binding overhead),
|
|
92
|
+
Much faster for tiny inputs (no native binding overhead), faster for medium, 2x slower for large
|
|
93
93
|
|
|
94
94
|
Run `npm run bench` to reproduce
|
|
95
95
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backward-references.d.ts","sourceRoot":"","sources":["../../src/encode/backward-references.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAsB,MAAM,SAAS,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAsC,MAAM,WAAW,CAAA;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,g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,EAAE,UAAU,GAAG,MAAM,CAM1E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAEhE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAEpE;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAOjF;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,GACnB,aAAa,CAOf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entropy-encode.d.ts","sourceRoot":"","sources":["../../src/encode/entropy-encode.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAClC,eAAO,MAAM,oBAAoB,IAAI,CAAA;AACrC,eAAO,MAAM,2BAA2B,KAAK,CAAA;AAC7C,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC,eAAO,MAAM,iBAAiB,KAAK,CAAA;AACnC,eAAO,MAAM,4BAA4B,IAAI,CAAA;AAI7C,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,WAAW,CAAA;CAClB;AAQD,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,WAAW,EACtB,SAAS,GAAE,MAAyB,GACnC,WAAW,
|
|
1
|
+
{"version":3,"file":"entropy-encode.d.ts","sourceRoot":"","sources":["../../src/encode/entropy-encode.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAClC,eAAO,MAAM,oBAAoB,IAAI,CAAA;AACrC,eAAO,MAAM,2BAA2B,KAAK,CAAA;AAC7C,eAAO,MAAM,uBAAuB,KAAK,CAAA;AACzC,eAAO,MAAM,iBAAiB,KAAK,CAAA;AACnC,eAAO,MAAM,4BAA4B,IAAI,CAAA;AAI7C,MAAM,WAAW,WA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B,GACtB,IAAI;IA+EP,cAAc,CACZ,IAAI,EAAE,UAAU,EAChB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,UAAU,EACzB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE;CA2EnB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAqBrF"}
|
package/dist/encode/match.d.ts
CHANGED
|
@@ -25,7 +25,6 @@ export declare function createSearchResult(): HasherSearchResult;
|
|
|
25
25
|
export declare function prepareDistanceCache(distanceCache: Int32Array, numDistances: number): void;
|
|
26
26
|
export declare function createDistanceCache(): Int32Array;
|
|
27
27
|
export declare const HASH_MUL_32 = 506832829;
|
|
28
|
-
export declare const HASH_MUL_64 = 506832829n;
|
|
29
28
|
export declare function hashBytes4(data: Uint8Array, pos: number, bucketBits: number): number;
|
|
30
29
|
export declare function hashBytes8(data: Uint8Array, pos: number, hashLen: number, bucketBits: number): number;
|
|
31
30
|
//# sourceMappingURL=match.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/encode/match.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,eAAO,MAAM,kBAAkB,MAAM,CAAA;AACrC,eAAO,MAAM,oBAAoB,KAAK,CAAA;AACtC,eAAO,MAAM,UAAU,QAA+B,CAAA;AACtD,eAAO,MAAM,aAAa,aAAa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ACZ,MAAM,CA8BR;AAED,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,MAAM,CAQR;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAOnF;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,GACnB,aAAa,CAOf;AAED,wBAAgB,kBAAkB,IAAI,kBAAkB,CAOvD;AAID,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAoB1F;AAED,wBAAgB,mBAAmB,IAAI,UAAU,CAQhD;AAED,eAAO,MAAM,WAAW,YAAa,CAAA;AAErC,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAUpF;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CA4CR"}
|
package/dist/encode.cjs
CHANGED
|
@@ -502,28 +502,15 @@ function backwardReferenceScoreUsingLastDistance(copyLength) {
|
|
|
502
502
|
function findMatchLength(data, s1, s2, limit) {
|
|
503
503
|
let matched = 0;
|
|
504
504
|
while (matched + 4 <= limit) {
|
|
505
|
-
if (data[s1 + matched] !== data[s2 + matched]
|
|
505
|
+
if (data[s1 + matched] !== data[s2 + matched]) return matched;
|
|
506
|
+
if (data[s1 + matched + 1] !== data[s2 + matched + 1]) return matched + 1;
|
|
507
|
+
if (data[s1 + matched + 2] !== data[s2 + matched + 2]) return matched + 2;
|
|
508
|
+
if (data[s1 + matched + 3] !== data[s2 + matched + 3]) return matched + 3;
|
|
506
509
|
matched += 4;
|
|
507
510
|
}
|
|
508
511
|
while (matched < limit && data[s1 + matched] === data[s2 + matched]) matched++;
|
|
509
512
|
return matched;
|
|
510
513
|
}
|
|
511
|
-
function createBackwardMatch(distance, length) {
|
|
512
|
-
return {
|
|
513
|
-
distance,
|
|
514
|
-
length,
|
|
515
|
-
score: backwardReferenceScore(length, distance),
|
|
516
|
-
lenCodeDelta: 0
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
function createSearchResult() {
|
|
520
|
-
return {
|
|
521
|
-
len: 0,
|
|
522
|
-
distance: 0,
|
|
523
|
-
score: 0,
|
|
524
|
-
lenCodeDelta: 0
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
514
|
function prepareDistanceCache(distanceCache, numDistances) {
|
|
528
515
|
if (numDistances > 4) {
|
|
529
516
|
const lastDistance = distanceCache[0];
|
|
@@ -545,24 +532,30 @@ function prepareDistanceCache(distanceCache, numDistances) {
|
|
|
545
532
|
}
|
|
546
533
|
}
|
|
547
534
|
const HASH_MUL_32 = 506832829;
|
|
548
|
-
const HASH_MUL_64 = 506832829n;
|
|
549
535
|
function hashBytes4(data, pos, bucketBits) {
|
|
550
|
-
const
|
|
551
|
-
const b1 = pos + 1 < data.length ? data[pos + 1] : 0;
|
|
552
|
-
const b2 = pos + 2 < data.length ? data[pos + 2] : 0;
|
|
553
|
-
const b3 = pos + 3 < data.length ? data[pos + 3] : 0;
|
|
554
|
-
const h32 = (b0 | b1 << 8 | b2 << 16 | b3 << 24) >>> 0;
|
|
536
|
+
const h32 = (data[pos] | data[pos + 1] << 8 | data[pos + 2] << 16 | data[pos + 3] << 24) >>> 0;
|
|
555
537
|
return Math.imul(h32, HASH_MUL_32) >>> 0 >>> 32 - bucketBits;
|
|
556
538
|
}
|
|
557
539
|
function hashBytes8(data, pos, hashLen, bucketBits) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const
|
|
561
|
-
|
|
540
|
+
if (hashLen === 5) {
|
|
541
|
+
const h32 = (data[pos] | data[pos + 1] << 8 | data[pos + 2] << 16 | data[pos + 3] << 24) >>> 0;
|
|
542
|
+
const b4 = data[pos + 4] | 0;
|
|
543
|
+
return Math.imul(h32 ^ b4 << 24, HASH_MUL_32) >>> 0 >>> 32 - bucketBits;
|
|
544
|
+
}
|
|
545
|
+
let h32 = (data[pos] | data[pos + 1] << 8 | data[pos + 2] << 16 | data[pos + 3] << 24) >>> 0;
|
|
546
|
+
if (hashLen <= 0) h32 = 0;
|
|
547
|
+
else if (hashLen === 1) h32 &= 255;
|
|
548
|
+
else if (hashLen === 2) h32 &= 65535;
|
|
549
|
+
else if (hashLen === 3) h32 &= 16777215;
|
|
550
|
+
if (hashLen > 4) {
|
|
551
|
+
const keep = hashLen - 4;
|
|
552
|
+
let tail = (data[pos + 4] | data[pos + 5] << 8 | data[pos + 6] << 16 | data[pos + 7] << 24) >>> 0;
|
|
553
|
+
if (keep === 1) tail &= 255;
|
|
554
|
+
else if (keep === 2) tail &= 65535;
|
|
555
|
+
else if (keep === 3) tail &= 16777215;
|
|
556
|
+
h32 ^= tail;
|
|
562
557
|
}
|
|
563
|
-
|
|
564
|
-
h64 = (h64 << shift) * HASH_MUL_64;
|
|
565
|
-
return Number(h64 >> BigInt(64 - bucketBits));
|
|
558
|
+
return Math.imul(h32, HASH_MUL_32) >>> 0 >>> 32 - bucketBits;
|
|
566
559
|
}
|
|
567
560
|
|
|
568
561
|
//#endregion
|
|
@@ -764,7 +757,15 @@ var HashChainHasher = class {
|
|
|
764
757
|
}
|
|
765
758
|
prevIx = this.chains[prevIx & this.windowMask];
|
|
766
759
|
}
|
|
767
|
-
|
|
760
|
+
for (let i = 1; i < matches.length; i++) {
|
|
761
|
+
const item = matches[i];
|
|
762
|
+
let j = i - 1;
|
|
763
|
+
while (j >= 0 && matches[j].length > item.length) {
|
|
764
|
+
matches[j + 1] = matches[j];
|
|
765
|
+
j--;
|
|
766
|
+
}
|
|
767
|
+
matches[j + 1] = item;
|
|
768
|
+
}
|
|
768
769
|
return matches;
|
|
769
770
|
}
|
|
770
771
|
};
|
|
@@ -848,7 +849,12 @@ var BinaryTreeHasher = class {
|
|
|
848
849
|
const len = curLen + findMatchLength(data, curIxMasked + curLen, prevIxMasked + curLen, maxLength - curLen);
|
|
849
850
|
if (matches && len > bestLen) {
|
|
850
851
|
bestLen = len;
|
|
851
|
-
result.push(
|
|
852
|
+
result.push({
|
|
853
|
+
distance: backward,
|
|
854
|
+
length: len,
|
|
855
|
+
score: backwardReferenceScore(len, backward),
|
|
856
|
+
lenCodeDelta: 0
|
|
857
|
+
});
|
|
852
858
|
}
|
|
853
859
|
if (len >= maxCompLen) {
|
|
854
860
|
if (shouldRerootTree) {
|
|
@@ -885,7 +891,12 @@ var BinaryTreeHasher = class {
|
|
|
885
891
|
const len = findMatchLength(data, prevIxMasked, curIxMasked, maxLength);
|
|
886
892
|
if (len > bestLen) {
|
|
887
893
|
bestLen = len;
|
|
888
|
-
matches.push(
|
|
894
|
+
matches.push({
|
|
895
|
+
distance: backward,
|
|
896
|
+
length: len,
|
|
897
|
+
score: backwardReferenceScore(len, backward),
|
|
898
|
+
lenCodeDelta: 0
|
|
899
|
+
});
|
|
889
900
|
}
|
|
890
901
|
}
|
|
891
902
|
if (bestLen < maxLength) {
|
|
@@ -895,7 +906,15 @@ var BinaryTreeHasher = class {
|
|
|
895
906
|
matches.push(m);
|
|
896
907
|
}
|
|
897
908
|
} else this.storeAndFindMatches(data, curIx, ringBufferMask, maxLength, maxBackward, null);
|
|
898
|
-
|
|
909
|
+
for (let i = 1; i < matches.length; i++) {
|
|
910
|
+
const item = matches[i];
|
|
911
|
+
let j = i - 1;
|
|
912
|
+
while (j >= 0 && matches[j].length > item.length) {
|
|
913
|
+
matches[j + 1] = matches[j];
|
|
914
|
+
j--;
|
|
915
|
+
}
|
|
916
|
+
matches[j + 1] = item;
|
|
917
|
+
}
|
|
899
918
|
return matches;
|
|
900
919
|
}
|
|
901
920
|
store(data, mask, ix) {
|
|
@@ -1137,6 +1156,12 @@ function createBackwardReferences(numBytes, position, ringbuffer, ringbufferMask
|
|
|
1137
1156
|
let pos = position;
|
|
1138
1157
|
const posEnd = position + numBytes;
|
|
1139
1158
|
const maxWindowBackward = (1 << 22) - 16;
|
|
1159
|
+
const result = {
|
|
1160
|
+
len: 0,
|
|
1161
|
+
distance: 0,
|
|
1162
|
+
score: 0,
|
|
1163
|
+
lenCodeDelta: 0
|
|
1164
|
+
};
|
|
1140
1165
|
while (pos < posEnd) {
|
|
1141
1166
|
const maxLen = posEnd - pos;
|
|
1142
1167
|
if (maxLen < 4) {
|
|
@@ -1145,7 +1170,10 @@ function createBackwardReferences(numBytes, position, ringbuffer, ringbufferMask
|
|
|
1145
1170
|
break;
|
|
1146
1171
|
}
|
|
1147
1172
|
const maxBackward = Math.min(pos, maxWindowBackward);
|
|
1148
|
-
|
|
1173
|
+
result.len = 0;
|
|
1174
|
+
result.distance = 0;
|
|
1175
|
+
result.score = 0;
|
|
1176
|
+
result.lenCodeDelta = 0;
|
|
1149
1177
|
hasher.findLongestMatch(ringbuffer, ringbufferMask, distCache, pos, Math.min(maxLen, 128), maxBackward, result);
|
|
1150
1178
|
if (result.len >= 4 && result.score > 0 && result.distance > 0) {
|
|
1151
1179
|
const distance = result.distance;
|
|
@@ -1764,43 +1792,43 @@ function createHuffmanTree(histogram, treeLimit = MAX_HUFFMAN_BITS) {
|
|
|
1764
1792
|
bits
|
|
1765
1793
|
};
|
|
1766
1794
|
}
|
|
1767
|
-
const
|
|
1795
|
+
const maxNodes = 2 * length + 2;
|
|
1796
|
+
const nodeCount = new Uint32Array(maxNodes);
|
|
1797
|
+
const nodeLeft = new Int32Array(maxNodes);
|
|
1798
|
+
const nodeRightOrValue = new Int32Array(maxNodes);
|
|
1768
1799
|
for (let countLimit = 1;; countLimit *= 2) {
|
|
1769
1800
|
let n = 0;
|
|
1770
1801
|
for (let i = length - 1; i >= 0; i--) if (histogram[i] > 0) {
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
indexRightOrValue: i
|
|
1776
|
-
};
|
|
1802
|
+
nodeCount[n] = Math.max(histogram[i], countLimit) >>> 0;
|
|
1803
|
+
nodeLeft[n] = -1;
|
|
1804
|
+
nodeRightOrValue[n] = i;
|
|
1805
|
+
n++;
|
|
1777
1806
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
tree[n + 1] = sentinel;
|
|
1807
|
+
sortHuffmanNodesSoA(nodeCount, nodeLeft, nodeRightOrValue, n);
|
|
1808
|
+
nodeCount[n] = 4294967295;
|
|
1809
|
+
nodeLeft[n] = -1;
|
|
1810
|
+
nodeRightOrValue[n] = -1;
|
|
1811
|
+
nodeCount[n + 1] = 4294967295;
|
|
1812
|
+
nodeLeft[n + 1] = -1;
|
|
1813
|
+
nodeRightOrValue[n + 1] = -1;
|
|
1786
1814
|
let i = 0;
|
|
1787
1815
|
let j = n + 1;
|
|
1788
1816
|
for (let k = n - 1; k > 0; k--) {
|
|
1789
1817
|
let left;
|
|
1790
|
-
if (
|
|
1818
|
+
if (nodeCount[i] <= nodeCount[j]) left = i++;
|
|
1791
1819
|
else left = j++;
|
|
1792
1820
|
let right;
|
|
1793
|
-
if (
|
|
1821
|
+
if (nodeCount[i] <= nodeCount[j]) right = i++;
|
|
1794
1822
|
else right = j++;
|
|
1795
1823
|
const jEnd = 2 * n - k;
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1824
|
+
nodeCount[jEnd] = nodeCount[left] + nodeCount[right] >>> 0;
|
|
1825
|
+
nodeLeft[jEnd] = left;
|
|
1826
|
+
nodeRightOrValue[jEnd] = right;
|
|
1827
|
+
nodeCount[jEnd + 1] = 4294967295;
|
|
1828
|
+
nodeLeft[jEnd + 1] = -1;
|
|
1829
|
+
nodeRightOrValue[jEnd + 1] = -1;
|
|
1802
1830
|
}
|
|
1803
|
-
if (
|
|
1831
|
+
if (setDepthSoA(2 * n - 1, nodeLeft, nodeRightOrValue, depths, treeLimit)) break;
|
|
1804
1832
|
depths.fill(0);
|
|
1805
1833
|
}
|
|
1806
1834
|
convertBitDepthsToSymbols(depths, bits);
|
|
@@ -1809,36 +1837,47 @@ function createHuffmanTree(histogram, treeLimit = MAX_HUFFMAN_BITS) {
|
|
|
1809
1837
|
bits
|
|
1810
1838
|
};
|
|
1811
1839
|
}
|
|
1812
|
-
function
|
|
1840
|
+
function setDepthSoA(root, nodeLeft, nodeRightOrValue, depths, maxDepth) {
|
|
1813
1841
|
const stack = new Int32Array(16);
|
|
1814
1842
|
let level = 0;
|
|
1815
1843
|
let p = root;
|
|
1816
1844
|
stack[0] = -1;
|
|
1817
1845
|
while (true) {
|
|
1818
|
-
|
|
1846
|
+
const left = nodeLeft[p];
|
|
1847
|
+
if (left >= 0) {
|
|
1819
1848
|
level++;
|
|
1820
1849
|
if (level > maxDepth) return false;
|
|
1821
|
-
stack[level] =
|
|
1822
|
-
p =
|
|
1850
|
+
stack[level] = nodeRightOrValue[p];
|
|
1851
|
+
p = left;
|
|
1823
1852
|
continue;
|
|
1824
|
-
} else depths[
|
|
1853
|
+
} else depths[nodeRightOrValue[p]] = level;
|
|
1825
1854
|
while (level >= 0 && stack[level] === -1) level--;
|
|
1826
1855
|
if (level < 0) return true;
|
|
1827
1856
|
p = stack[level];
|
|
1828
1857
|
stack[level] = -1;
|
|
1829
1858
|
}
|
|
1830
1859
|
}
|
|
1831
|
-
function
|
|
1860
|
+
function sortHuffmanNodesSoA(nodeCount, nodeLeft, nodeRightOrValue, n) {
|
|
1861
|
+
const less = (aCount, aVal, bCount, bVal) => {
|
|
1862
|
+
if (aCount !== bCount) return aCount < bCount;
|
|
1863
|
+
return aVal > bVal;
|
|
1864
|
+
};
|
|
1832
1865
|
if (n < 13) for (let i = 1; i < n; i++) {
|
|
1833
|
-
const
|
|
1866
|
+
const tmpCount = nodeCount[i];
|
|
1867
|
+
const tmpLeft = nodeLeft[i];
|
|
1868
|
+
const tmpRightOrVal = nodeRightOrValue[i];
|
|
1834
1869
|
let k = i;
|
|
1835
1870
|
let j = i - 1;
|
|
1836
|
-
while (j >= 0 &&
|
|
1837
|
-
|
|
1871
|
+
while (j >= 0 && less(tmpCount, tmpRightOrVal, nodeCount[j], nodeRightOrValue[j])) {
|
|
1872
|
+
nodeCount[k] = nodeCount[j];
|
|
1873
|
+
nodeLeft[k] = nodeLeft[j];
|
|
1874
|
+
nodeRightOrValue[k] = nodeRightOrValue[j];
|
|
1838
1875
|
k = j;
|
|
1839
1876
|
j--;
|
|
1840
1877
|
}
|
|
1841
|
-
|
|
1878
|
+
nodeCount[k] = tmpCount;
|
|
1879
|
+
nodeLeft[k] = tmpLeft;
|
|
1880
|
+
nodeRightOrValue[k] = tmpRightOrVal;
|
|
1842
1881
|
}
|
|
1843
1882
|
else {
|
|
1844
1883
|
const startGap = n < 57 ? 2 : 0;
|
|
@@ -1846,20 +1885,22 @@ function sortHuffmanNodes(nodes, n) {
|
|
|
1846
1885
|
const gap = SHELL_GAPS[g];
|
|
1847
1886
|
for (let i = gap; i < n; i++) {
|
|
1848
1887
|
let j = i;
|
|
1849
|
-
const
|
|
1850
|
-
|
|
1851
|
-
|
|
1888
|
+
const tmpCount = nodeCount[i];
|
|
1889
|
+
const tmpLeft = nodeLeft[i];
|
|
1890
|
+
const tmpRightOrVal = nodeRightOrValue[i];
|
|
1891
|
+
while (j >= gap && less(tmpCount, tmpRightOrVal, nodeCount[j - gap], nodeRightOrValue[j - gap])) {
|
|
1892
|
+
nodeCount[j] = nodeCount[j - gap];
|
|
1893
|
+
nodeLeft[j] = nodeLeft[j - gap];
|
|
1894
|
+
nodeRightOrValue[j] = nodeRightOrValue[j - gap];
|
|
1852
1895
|
j -= gap;
|
|
1853
1896
|
}
|
|
1854
|
-
|
|
1897
|
+
nodeCount[j] = tmpCount;
|
|
1898
|
+
nodeLeft[j] = tmpLeft;
|
|
1899
|
+
nodeRightOrValue[j] = tmpRightOrVal;
|
|
1855
1900
|
}
|
|
1856
1901
|
}
|
|
1857
1902
|
}
|
|
1858
1903
|
}
|
|
1859
|
-
function compareNodes(a, b) {
|
|
1860
|
-
if (a.totalCount !== b.totalCount) return a.totalCount < b.totalCount;
|
|
1861
|
-
return a.indexRightOrValue > b.indexRightOrValue;
|
|
1862
|
-
}
|
|
1863
1904
|
function reverseBits(numBits, bits) {
|
|
1864
1905
|
const LUT = [
|
|
1865
1906
|
0,
|