@maplibre/mlt 1.1.2 → 1.1.5
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/dist/decoding/decodingTestUtils.d.ts +75 -0
- package/dist/decoding/decodingTestUtils.js +285 -0
- package/dist/decoding/decodingTestUtils.js.map +1 -0
- package/dist/decoding/decodingUtils.d.ts +5 -8
- package/dist/decoding/decodingUtils.js +22 -49
- package/dist/decoding/decodingUtils.js.map +1 -1
- package/dist/decoding/decodingUtils.spec.js +85 -69
- package/dist/decoding/decodingUtils.spec.js.map +1 -1
- package/dist/decoding/fsstDecoder.spec.js +52 -35
- package/dist/decoding/fsstDecoder.spec.js.map +1 -1
- package/dist/decoding/geometryDecoder.js +41 -30
- package/dist/decoding/geometryDecoder.js.map +1 -1
- package/dist/decoding/integerDecodingUtils.d.ts +18 -31
- package/dist/decoding/integerDecodingUtils.js +134 -299
- package/dist/decoding/integerDecodingUtils.js.map +1 -1
- package/dist/decoding/integerDecodingUtils.spec.js +254 -148
- package/dist/decoding/integerDecodingUtils.spec.js.map +1 -1
- package/dist/decoding/integerStreamDecoder.d.ts +4 -6
- package/dist/decoding/integerStreamDecoder.js +104 -122
- package/dist/decoding/integerStreamDecoder.js.map +1 -1
- package/dist/decoding/integerStreamDecoder.spec.js +370 -131
- package/dist/decoding/integerStreamDecoder.spec.js.map +1 -1
- package/dist/decoding/propertyDecoder.js +14 -24
- package/dist/decoding/propertyDecoder.js.map +1 -1
- package/dist/decoding/propertyDecoder.spec.js +409 -606
- package/dist/decoding/propertyDecoder.spec.js.map +1 -1
- package/dist/decoding/stringDecoder.js +10 -10
- package/dist/decoding/stringDecoder.js.map +1 -1
- package/dist/decoding/stringDecoder.spec.js +352 -320
- package/dist/decoding/stringDecoder.spec.js.map +1 -1
- package/dist/decoding/unpackNullableUtils.d.ts +25 -0
- package/dist/decoding/unpackNullableUtils.js +51 -0
- package/dist/decoding/unpackNullableUtils.js.map +1 -0
- package/dist/decoding/unpackNullableUtils.spec.js +71 -0
- package/dist/decoding/unpackNullableUtils.spec.js.map +1 -0
- package/dist/encoding/embeddedTilesetMetadataEncoder.d.ts +16 -0
- package/dist/encoding/embeddedTilesetMetadataEncoder.js +40 -0
- package/dist/encoding/embeddedTilesetMetadataEncoder.js.map +1 -0
- package/dist/encoding/encodingUtils.d.ts +7 -0
- package/dist/encoding/encodingUtils.js +107 -0
- package/dist/encoding/encodingUtils.js.map +1 -0
- package/dist/encoding/fsstEncoder.d.ts +21 -0
- package/dist/encoding/fsstEncoder.js +78 -0
- package/dist/encoding/fsstEncoder.js.map +1 -0
- package/dist/encoding/integerEncodingUtils.d.ts +68 -0
- package/dist/encoding/integerEncodingUtils.js +655 -0
- package/dist/encoding/integerEncodingUtils.js.map +1 -0
- package/dist/encoding/integerStreamEncoder.d.ts +27 -0
- package/dist/encoding/integerStreamEncoder.js +139 -0
- package/dist/encoding/integerStreamEncoder.js.map +1 -0
- package/dist/encoding/packNullableUtils.d.ts +4 -0
- package/dist/encoding/packNullableUtils.js +55 -0
- package/dist/encoding/packNullableUtils.js.map +1 -0
- package/dist/encoding/propertyEncoder.d.ts +78 -0
- package/dist/encoding/propertyEncoder.js +335 -0
- package/dist/encoding/propertyEncoder.js.map +1 -0
- package/dist/encoding/stringEncoder.d.ts +12 -0
- package/dist/encoding/stringEncoder.js +182 -0
- package/dist/encoding/stringEncoder.js.map +1 -0
- package/dist/encoding/zOrderCurveEncoder.d.ts +1 -0
- package/dist/encoding/zOrderCurveEncoder.js +10 -0
- package/dist/encoding/zOrderCurveEncoder.js.map +1 -0
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.d.ts +5 -1
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.js +29 -41
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.js.map +1 -1
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.spec.d.ts +1 -0
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.spec.js +142 -0
- package/dist/metadata/tileset/embeddedTilesetMetadataDecoder.spec.js.map +1 -0
- package/dist/mltDecoder.js +2 -3
- package/dist/mltDecoder.js.map +1 -1
- package/dist/vector/dictionary/stringDictionaryVector.d.ts +1 -1
- package/dist/vector/dictionary/stringDictionaryVector.js.map +1 -1
- package/dist/vector/flat/stringFlatVector.d.ts +1 -1
- package/dist/vector/flat/stringFlatVector.js.map +1 -1
- package/dist/vector/fsst-dictionary/stringFsstDictionaryVector.d.ts +1 -1
- package/dist/vector/fsst-dictionary/stringFsstDictionaryVector.js.map +1 -1
- package/dist/vector/fsst-dictionary/stringFsstDictionaryVector.spec.js +2 -2
- package/dist/vector/fsst-dictionary/stringFsstDictionaryVector.spec.js.map +1 -1
- package/dist/vector/geometry/constGpuVector.d.ts +2 -2
- package/dist/vector/geometry/constGpuVector.js.map +1 -1
- package/dist/vector/geometry/flatGpuVector.d.ts +2 -2
- package/dist/vector/geometry/flatGpuVector.js.map +1 -1
- package/dist/vector/geometry/gpuVector.d.ts +2 -2
- package/dist/vector/geometry/gpuVector.js.map +1 -1
- package/dist/vector/geometry/topologyVector.d.ts +4 -4
- package/dist/vector/geometry/topologyVector.js +0 -1
- package/dist/vector/geometry/topologyVector.js.map +1 -1
- package/dist/vector/geometry/zOrderCurve.spec.js +17 -11
- package/dist/vector/geometry/zOrderCurve.spec.js.map +1 -1
- package/dist/vector/variableSizeVector.d.ts +2 -2
- package/dist/vector/variableSizeVector.js +0 -1
- package/dist/vector/variableSizeVector.js.map +1 -1
- package/package.json +6 -8
- package/dist/decoding/geometryDecoder.spec.js +0 -5
- package/dist/decoding/geometryDecoder.spec.js.map +0 -1
- /package/dist/decoding/{geometryDecoder.spec.d.ts → unpackNullableUtils.spec.d.ts} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* Null suppression (physical level) techniques ------------------------------------------------------------------*/
|
|
2
1
|
//based on https://github.com/mapbox/pbf/blob/main/index.js
|
|
3
2
|
export function decodeVarintInt32(buf, bufferOffset, numValues) {
|
|
4
3
|
const dst = new Int32Array(numValues);
|
|
@@ -39,21 +38,42 @@ export function decodeVarintInt32(buf, bufferOffset, numValues) {
|
|
|
39
38
|
export function decodeVarintInt64(src, offset, numValues) {
|
|
40
39
|
const dst = new BigInt64Array(numValues);
|
|
41
40
|
for (let i = 0; i < dst.length; i++) {
|
|
42
|
-
dst[i] =
|
|
41
|
+
dst[i] = decodeVarintInt64Value(src, offset);
|
|
43
42
|
}
|
|
44
43
|
return dst;
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
// Source: https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/util/VarInt.java
|
|
46
|
+
function decodeVarintInt64Value(bytes, pos) {
|
|
47
|
+
let value = 0n;
|
|
48
|
+
let shift = 0;
|
|
49
|
+
let index = pos.get();
|
|
50
|
+
while (index < bytes.length) {
|
|
51
|
+
const b = bytes[index++];
|
|
52
|
+
value |= BigInt(b & 0x7f) << BigInt(shift);
|
|
53
|
+
if ((b & 0x80) === 0) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
shift += 7;
|
|
57
|
+
if (shift >= 64) {
|
|
58
|
+
throw new Error("Varint too long");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
pos.set(index);
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
/*
|
|
65
|
+
* Since decoding Int64 values to BigInt is more than an order of magnitude slower in the tests then using a Float64,
|
|
66
|
+
* this decoding method limits the max size of a Long value to 53 bits
|
|
67
|
+
*/
|
|
68
|
+
export function decodeVarintFloat64(src, offset, numValues) {
|
|
49
69
|
const dst = new Float64Array(numValues);
|
|
50
70
|
for (let i = 0; i < numValues; i++) {
|
|
51
|
-
dst[i] =
|
|
71
|
+
dst[i] = decodeVarintFloat64Value(src, offset);
|
|
52
72
|
}
|
|
53
73
|
return dst;
|
|
54
74
|
}
|
|
55
75
|
//based on https://github.com/mapbox/pbf/blob/main/index.js
|
|
56
|
-
function
|
|
76
|
+
function decodeVarintFloat64Value(buf, offset) {
|
|
57
77
|
let val, b;
|
|
58
78
|
b = buf[offset.get()];
|
|
59
79
|
offset.increment();
|
|
@@ -116,67 +136,38 @@ function decodeVarintRemainder(l, buf, offset) {
|
|
|
116
136
|
export function decodeFastPfor(data, numValues, byteLength, offset) {
|
|
117
137
|
throw new Error("FastPFor is not implemented yet.");
|
|
118
138
|
}
|
|
119
|
-
export function
|
|
139
|
+
export function decodeZigZagInt32Value(encoded) {
|
|
140
|
+
return (encoded >>> 1) ^ -(encoded & 1);
|
|
141
|
+
}
|
|
142
|
+
export function decodeZigZagInt64Value(encoded) {
|
|
143
|
+
return (encoded >> 1n) ^ -(encoded & 1n);
|
|
144
|
+
}
|
|
145
|
+
export function decodeZigZagFloat64Value(encoded) {
|
|
146
|
+
return encoded % 2 === 1 ? (encoded + 1) / -2 : encoded / 2;
|
|
147
|
+
}
|
|
148
|
+
export function decodeZigZagInt32(encodedData) {
|
|
120
149
|
for (let i = 0; i < encodedData.length; i++) {
|
|
121
|
-
|
|
122
|
-
encodedData[i] = (encoded >>> 1) ^ -(encoded & 1);
|
|
150
|
+
encodedData[i] = decodeZigZagInt32Value(encodedData[i]);
|
|
123
151
|
}
|
|
124
152
|
}
|
|
125
153
|
export function decodeZigZagInt64(encodedData) {
|
|
126
154
|
for (let i = 0; i < encodedData.length; i++) {
|
|
127
|
-
|
|
128
|
-
encodedData[i] = (encoded >> 1n) ^ -(encoded & 1n);
|
|
155
|
+
encodedData[i] = decodeZigZagInt64Value(encodedData[i]);
|
|
129
156
|
}
|
|
130
157
|
}
|
|
131
158
|
export function decodeZigZagFloat64(encodedData) {
|
|
132
159
|
for (let i = 0; i < encodedData.length; i++) {
|
|
133
|
-
|
|
134
|
-
//Get rid of branch? -> var v = encoded % 2 && 1; encodedData[i] = (encoded + v) / (v * 2 - 1) * 2;
|
|
135
|
-
encodedData[i] = encoded % 2 === 1 ? (encoded + 1) / -2 : encoded / 2;
|
|
160
|
+
encodedData[i] = decodeZigZagFloat64Value(encodedData[i]);
|
|
136
161
|
}
|
|
137
162
|
}
|
|
138
|
-
export function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// Source: https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/util/VarInt.java
|
|
145
|
-
function decodeSingleVarintInt64(bytes, pos) {
|
|
146
|
-
let value = 0n;
|
|
147
|
-
let shift = 0;
|
|
148
|
-
let index = pos.get();
|
|
149
|
-
while (index < bytes.length) {
|
|
150
|
-
const b = bytes[index++];
|
|
151
|
-
value |= BigInt(b & 0x7f) << BigInt(shift);
|
|
152
|
-
if ((b & 0x80) === 0) {
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
shift += 7;
|
|
156
|
-
if (shift >= 64) {
|
|
157
|
-
throw new Error("Varint too long");
|
|
163
|
+
export function decodeUnsignedRleInt32(encodedData, numRuns, numTotalValues) {
|
|
164
|
+
// If numTotalValues not provided, calculate from runs (nullable case)
|
|
165
|
+
if (numTotalValues === undefined) {
|
|
166
|
+
numTotalValues = 0;
|
|
167
|
+
for (let i = 0; i < numRuns; i++) {
|
|
168
|
+
numTotalValues += encodedData[i];
|
|
158
169
|
}
|
|
159
170
|
}
|
|
160
|
-
pos.set(index);
|
|
161
|
-
return value;
|
|
162
|
-
}
|
|
163
|
-
/* Logical Level Techniques Flat Vectors ------------------------------------------------------------------ */
|
|
164
|
-
export function decodeRle(data, streamMetadata, isSigned) {
|
|
165
|
-
return isSigned
|
|
166
|
-
? decodeZigZagRle(data, streamMetadata.runs, streamMetadata.numRleValues)
|
|
167
|
-
: decodeUnsignedRle(data, streamMetadata.runs, streamMetadata.numRleValues);
|
|
168
|
-
}
|
|
169
|
-
export function decodeRleInt64(data, streamMetadata, isSigned) {
|
|
170
|
-
return isSigned
|
|
171
|
-
? decodeZigZagRleInt64(data, streamMetadata.runs, streamMetadata.numRleValues)
|
|
172
|
-
: decodeUnsignedRleInt64(data, streamMetadata.runs, streamMetadata.numRleValues);
|
|
173
|
-
}
|
|
174
|
-
export function decodeRleFloat64(data, streamMetadata, isSigned) {
|
|
175
|
-
return isSigned
|
|
176
|
-
? decodeZigZagRleFloat64(data, streamMetadata.runs, streamMetadata.numRleValues)
|
|
177
|
-
: decodeUnsignedRleFloat64(data, streamMetadata.runs, streamMetadata.numRleValues);
|
|
178
|
-
}
|
|
179
|
-
export function decodeUnsignedRle(encodedData, numRuns, numTotalValues) {
|
|
180
171
|
const decodedValues = new Int32Array(numTotalValues);
|
|
181
172
|
let offset = 0;
|
|
182
173
|
for (let i = 0; i < numRuns; i++) {
|
|
@@ -188,6 +179,13 @@ export function decodeUnsignedRle(encodedData, numRuns, numTotalValues) {
|
|
|
188
179
|
return decodedValues;
|
|
189
180
|
}
|
|
190
181
|
export function decodeUnsignedRleInt64(encodedData, numRuns, numTotalValues) {
|
|
182
|
+
// If numTotalValues not provided, calculate from runs (nullable case)
|
|
183
|
+
if (numTotalValues === undefined) {
|
|
184
|
+
numTotalValues = 0;
|
|
185
|
+
for (let i = 0; i < numRuns; i++) {
|
|
186
|
+
numTotalValues += Number(encodedData[i]);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
191
189
|
const decodedValues = new BigInt64Array(numTotalValues);
|
|
192
190
|
let offset = 0;
|
|
193
191
|
for (let i = 0; i < numRuns; i++) {
|
|
@@ -213,8 +211,8 @@ export function decodeUnsignedRleFloat64(encodedData, numRuns, numTotalValues) {
|
|
|
213
211
|
* In place decoding of the zigzag encoded delta values.
|
|
214
212
|
* Inspired by https://github.com/lemire/JavaFastPFOR/blob/master/src/main/java/me/lemire/integercompression/differential/Delta.java
|
|
215
213
|
*/
|
|
216
|
-
export function
|
|
217
|
-
data[0] = (data[0]
|
|
214
|
+
export function decodeZigZagDeltaInt32(data) {
|
|
215
|
+
data[0] = decodeZigZagInt32Value(data[0]);
|
|
218
216
|
const sz0 = (data.length / 4) * 4;
|
|
219
217
|
let i = 1;
|
|
220
218
|
if (sz0 >= 4) {
|
|
@@ -223,18 +221,18 @@ export function decodeZigZagDelta(data) {
|
|
|
223
221
|
const data2 = data[i + 1];
|
|
224
222
|
const data3 = data[i + 2];
|
|
225
223
|
const data4 = data[i + 3];
|
|
226
|
-
data[i] = (
|
|
227
|
-
data[i + 1] = (
|
|
228
|
-
data[i + 2] = (
|
|
229
|
-
data[i + 3] = (
|
|
224
|
+
data[i] = decodeZigZagInt32Value(data1) + data[i - 1];
|
|
225
|
+
data[i + 1] = decodeZigZagInt32Value(data2) + data[i];
|
|
226
|
+
data[i + 2] = decodeZigZagInt32Value(data3) + data[i + 1];
|
|
227
|
+
data[i + 3] = decodeZigZagInt32Value(data4) + data[i + 2];
|
|
230
228
|
}
|
|
231
229
|
}
|
|
232
230
|
for (; i != data.length; ++i) {
|
|
233
|
-
data[i] = (
|
|
231
|
+
data[i] = decodeZigZagInt32Value(data[i]) + data[i - 1];
|
|
234
232
|
}
|
|
235
233
|
}
|
|
236
234
|
export function decodeZigZagDeltaInt64(data) {
|
|
237
|
-
data[0] = (data[0]
|
|
235
|
+
data[0] = decodeZigZagInt64Value(data[0]);
|
|
238
236
|
const sz0 = (data.length / 4) * 4;
|
|
239
237
|
let i = 1;
|
|
240
238
|
if (sz0 >= 4) {
|
|
@@ -243,18 +241,18 @@ export function decodeZigZagDeltaInt64(data) {
|
|
|
243
241
|
const data2 = data[i + 1];
|
|
244
242
|
const data3 = data[i + 2];
|
|
245
243
|
const data4 = data[i + 3];
|
|
246
|
-
data[i] = (
|
|
247
|
-
data[i + 1] = (
|
|
248
|
-
data[i + 2] = (
|
|
249
|
-
data[i + 3] = (
|
|
244
|
+
data[i] = decodeZigZagInt64Value(data1) + data[i - 1];
|
|
245
|
+
data[i + 1] = decodeZigZagInt64Value(data2) + data[i];
|
|
246
|
+
data[i + 2] = decodeZigZagInt64Value(data3) + data[i + 1];
|
|
247
|
+
data[i + 3] = decodeZigZagInt64Value(data4) + data[i + 2];
|
|
250
248
|
}
|
|
251
249
|
}
|
|
252
250
|
for (; i != data.length; ++i) {
|
|
253
|
-
data[i] = (
|
|
251
|
+
data[i] = decodeZigZagInt64Value(data[i]) + data[i - 1];
|
|
254
252
|
}
|
|
255
253
|
}
|
|
256
254
|
export function decodeZigZagDeltaFloat64(data) {
|
|
257
|
-
data[0] =
|
|
255
|
+
data[0] = decodeZigZagFloat64Value(data[0]);
|
|
258
256
|
const sz0 = (data.length / 4) * 4;
|
|
259
257
|
let i = 1;
|
|
260
258
|
if (sz0 >= 4) {
|
|
@@ -263,35 +261,49 @@ export function decodeZigZagDeltaFloat64(data) {
|
|
|
263
261
|
const data2 = data[i + 1];
|
|
264
262
|
const data3 = data[i + 2];
|
|
265
263
|
const data4 = data[i + 3];
|
|
266
|
-
data[i] = (data1
|
|
267
|
-
data[i + 1] = (data2
|
|
268
|
-
data[i + 2] = (data3
|
|
269
|
-
data[i + 3] = (data4
|
|
264
|
+
data[i] = decodeZigZagFloat64Value(data1) + data[i - 1];
|
|
265
|
+
data[i + 1] = decodeZigZagFloat64Value(data2) + data[i];
|
|
266
|
+
data[i + 2] = decodeZigZagFloat64Value(data3) + data[i + 1];
|
|
267
|
+
data[i + 3] = decodeZigZagFloat64Value(data4) + data[i + 2];
|
|
270
268
|
}
|
|
271
269
|
}
|
|
272
270
|
for (; i != data.length; ++i) {
|
|
273
|
-
data[i] = (data[i]
|
|
271
|
+
data[i] = decodeZigZagFloat64Value(data[i]) + data[i - 1];
|
|
274
272
|
}
|
|
275
273
|
}
|
|
276
|
-
export function
|
|
274
|
+
export function decodeZigZagRleInt32(data, numRuns, numTotalValues) {
|
|
275
|
+
// If numTotalValues not provided, calculate from runs (nullable case)
|
|
276
|
+
if (numTotalValues === undefined) {
|
|
277
|
+
numTotalValues = 0;
|
|
278
|
+
for (let i = 0; i < numRuns; i++) {
|
|
279
|
+
numTotalValues += data[i];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
277
282
|
const decodedValues = new Int32Array(numTotalValues);
|
|
278
283
|
let offset = 0;
|
|
279
284
|
for (let i = 0; i < numRuns; i++) {
|
|
280
285
|
const runLength = data[i];
|
|
281
286
|
let value = data[i + numRuns];
|
|
282
|
-
value = (value
|
|
287
|
+
value = decodeZigZagInt32Value(value);
|
|
283
288
|
decodedValues.fill(value, offset, offset + runLength);
|
|
284
289
|
offset += runLength;
|
|
285
290
|
}
|
|
286
291
|
return decodedValues;
|
|
287
292
|
}
|
|
288
293
|
export function decodeZigZagRleInt64(data, numRuns, numTotalValues) {
|
|
294
|
+
// If numTotalValues not provided, calculate from runs (nullable case)
|
|
295
|
+
if (numTotalValues === undefined) {
|
|
296
|
+
numTotalValues = 0;
|
|
297
|
+
for (let i = 0; i < numRuns; i++) {
|
|
298
|
+
numTotalValues += Number(data[i]);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
289
301
|
const decodedValues = new BigInt64Array(numTotalValues);
|
|
290
302
|
let offset = 0;
|
|
291
303
|
for (let i = 0; i < numRuns; i++) {
|
|
292
304
|
const runLength = Number(data[i]);
|
|
293
305
|
let value = data[i + numRuns];
|
|
294
|
-
value = (value
|
|
306
|
+
value = decodeZigZagInt64Value(value);
|
|
295
307
|
decodedValues.fill(value, offset, offset + runLength);
|
|
296
308
|
offset += runLength;
|
|
297
309
|
}
|
|
@@ -303,8 +315,7 @@ export function decodeZigZagRleFloat64(data, numRuns, numTotalValues) {
|
|
|
303
315
|
for (let i = 0; i < numRuns; i++) {
|
|
304
316
|
const runLength = data[i];
|
|
305
317
|
let value = data[i + numRuns];
|
|
306
|
-
|
|
307
|
-
value = value % 2 === 1 ? (value + 1) / -2 : value / 2;
|
|
318
|
+
value = decodeZigZagFloat64Value(value);
|
|
308
319
|
decodedValues.fill(value, offset, offset + runLength);
|
|
309
320
|
offset += runLength;
|
|
310
321
|
}
|
|
@@ -341,8 +352,10 @@ export function inverseDelta(data) {
|
|
|
341
352
|
* Inspired by https://github.com/lemire/JavaFastPFOR/blob/master/src/main/java/me/lemire/integercompression/differential/Delta.java
|
|
342
353
|
*/
|
|
343
354
|
export function decodeComponentwiseDeltaVec2(data) {
|
|
344
|
-
|
|
345
|
-
|
|
355
|
+
if (data.length < 2)
|
|
356
|
+
return;
|
|
357
|
+
data[0] = decodeZigZagInt32Value(data[0]);
|
|
358
|
+
data[1] = decodeZigZagInt32Value(data[1]);
|
|
346
359
|
const sz0 = (data.length / 4) * 4;
|
|
347
360
|
let i = 2;
|
|
348
361
|
if (sz0 >= 4) {
|
|
@@ -351,20 +364,22 @@ export function decodeComponentwiseDeltaVec2(data) {
|
|
|
351
364
|
const y1 = data[i + 1];
|
|
352
365
|
const x2 = data[i + 2];
|
|
353
366
|
const y2 = data[i + 3];
|
|
354
|
-
data[i] = (
|
|
355
|
-
data[i + 1] = (
|
|
356
|
-
data[i + 2] = (
|
|
357
|
-
data[i + 3] = (
|
|
367
|
+
data[i] = decodeZigZagInt32Value(x1) + data[i - 2];
|
|
368
|
+
data[i + 1] = decodeZigZagInt32Value(y1) + data[i - 1];
|
|
369
|
+
data[i + 2] = decodeZigZagInt32Value(x2) + data[i];
|
|
370
|
+
data[i + 3] = decodeZigZagInt32Value(y2) + data[i + 1];
|
|
358
371
|
}
|
|
359
372
|
}
|
|
360
373
|
for (; i != data.length; i += 2) {
|
|
361
|
-
data[i] = (
|
|
362
|
-
data[i + 1] = (
|
|
374
|
+
data[i] = decodeZigZagInt32Value(data[i]) + data[i - 2];
|
|
375
|
+
data[i + 1] = decodeZigZagInt32Value(data[i + 1]) + data[i - 1];
|
|
363
376
|
}
|
|
364
377
|
}
|
|
365
378
|
export function decodeComponentwiseDeltaVec2Scaled(data, scale, min, max) {
|
|
366
|
-
|
|
367
|
-
|
|
379
|
+
if (data.length < 2)
|
|
380
|
+
return;
|
|
381
|
+
let previousVertexX = decodeZigZagInt32Value(data[0]);
|
|
382
|
+
let previousVertexY = decodeZigZagInt32Value(data[1]);
|
|
368
383
|
data[0] = clamp(Math.round(previousVertexX * scale), min, max);
|
|
369
384
|
data[1] = clamp(Math.round(previousVertexY * scale), min, max);
|
|
370
385
|
const sz0 = data.length / 16;
|
|
@@ -373,21 +388,21 @@ export function decodeComponentwiseDeltaVec2Scaled(data, scale, min, max) {
|
|
|
373
388
|
for (; i < sz0 - 4; i += 4) {
|
|
374
389
|
const x1 = data[i];
|
|
375
390
|
const y1 = data[i + 1];
|
|
376
|
-
const currentVertexX = (
|
|
377
|
-
const currentVertexY = (
|
|
391
|
+
const currentVertexX = decodeZigZagInt32Value(x1) + previousVertexX;
|
|
392
|
+
const currentVertexY = decodeZigZagInt32Value(y1) + previousVertexY;
|
|
378
393
|
data[i] = clamp(Math.round(currentVertexX * scale), min, max);
|
|
379
394
|
data[i + 1] = clamp(Math.round(currentVertexY * scale), min, max);
|
|
380
395
|
const x2 = data[i + 2];
|
|
381
396
|
const y2 = data[i + 3];
|
|
382
|
-
previousVertexX = (
|
|
383
|
-
previousVertexY = (
|
|
397
|
+
previousVertexX = decodeZigZagInt32Value(x2) + currentVertexX;
|
|
398
|
+
previousVertexY = decodeZigZagInt32Value(y2) + currentVertexY;
|
|
384
399
|
data[i + 2] = clamp(Math.round(previousVertexX * scale), min, max);
|
|
385
400
|
data[i + 3] = clamp(Math.round(previousVertexY * scale), min, max);
|
|
386
401
|
}
|
|
387
402
|
}
|
|
388
403
|
for (; i != data.length; i += 2) {
|
|
389
|
-
previousVertexX += (data[i]
|
|
390
|
-
previousVertexY += (data[i + 1]
|
|
404
|
+
previousVertexX += decodeZigZagInt32Value(data[i]);
|
|
405
|
+
previousVertexY += decodeZigZagInt32Value(data[i + 1]);
|
|
391
406
|
data[i] = clamp(Math.round(previousVertexX * scale), min, max);
|
|
392
407
|
data[i + 1] = clamp(Math.round(previousVertexY * scale), min, max);
|
|
393
408
|
}
|
|
@@ -395,58 +410,21 @@ export function decodeComponentwiseDeltaVec2Scaled(data, scale, min, max) {
|
|
|
395
410
|
function clamp(n, min, max) {
|
|
396
411
|
return Math.min(max, Math.max(min, n));
|
|
397
412
|
}
|
|
398
|
-
export function decodeNullableZigZagDelta(bitVector, data) {
|
|
399
|
-
const decodedData = new Int32Array(bitVector.size());
|
|
400
|
-
let dataCounter = 0;
|
|
401
|
-
if (bitVector.get(0)) {
|
|
402
|
-
decodedData[0] = bitVector.get(0) ? (data[0] >>> 1) ^ -(data[0] & 1) : 0;
|
|
403
|
-
dataCounter = 1;
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
decodedData[0] = 0;
|
|
407
|
-
}
|
|
408
|
-
let i = 1;
|
|
409
|
-
for (; i != decodedData.length; ++i) {
|
|
410
|
-
decodedData[i] = bitVector.get(i)
|
|
411
|
-
? decodedData[i - 1] + ((data[dataCounter] >>> 1) ^ -(data[dataCounter++] & 1))
|
|
412
|
-
: decodedData[i - 1];
|
|
413
|
-
}
|
|
414
|
-
return decodedData;
|
|
415
|
-
}
|
|
416
|
-
export function decodeNullableZigZagDeltaInt64(bitVector, data) {
|
|
417
|
-
const decodedData = new BigInt64Array(bitVector.size());
|
|
418
|
-
let dataCounter = 0;
|
|
419
|
-
if (bitVector.get(0)) {
|
|
420
|
-
decodedData[0] = bitVector.get(0) ? (data[0] >> 1n) ^ -(data[0] & 1n) : 0n;
|
|
421
|
-
dataCounter = 1;
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
decodedData[0] = 0n;
|
|
425
|
-
}
|
|
426
|
-
let i = 1;
|
|
427
|
-
for (; i != decodedData.length; ++i) {
|
|
428
|
-
decodedData[i] = bitVector.get(i)
|
|
429
|
-
? decodedData[i - 1] + ((data[dataCounter] >> 1n) ^ -(data[dataCounter++] & 1n))
|
|
430
|
-
: decodedData[i - 1];
|
|
431
|
-
}
|
|
432
|
-
return decodedData;
|
|
433
|
-
}
|
|
434
413
|
/* Transform data to allow util access ------------------------------------------------------------------------ */
|
|
435
|
-
export function
|
|
414
|
+
export function decodeZigZagDeltaOfDeltaInt32(data) {
|
|
436
415
|
const decodedData = new Int32Array(data.length + 1);
|
|
437
416
|
decodedData[0] = 0;
|
|
438
|
-
decodedData[1] =
|
|
417
|
+
decodedData[1] = decodeZigZagInt32Value(data[0]);
|
|
439
418
|
let deltaSum = decodedData[1];
|
|
440
|
-
let i = 2;
|
|
441
|
-
for (; i != decodedData.length; ++i) {
|
|
419
|
+
for (let i = 2; i != decodedData.length; ++i) {
|
|
442
420
|
const zigZagValue = data[i - 1];
|
|
443
|
-
const delta = (zigZagValue
|
|
421
|
+
const delta = decodeZigZagInt32Value(zigZagValue);
|
|
444
422
|
deltaSum += delta;
|
|
445
423
|
decodedData[i] = decodedData[i - 1] + deltaSum;
|
|
446
424
|
}
|
|
447
|
-
return decodedData;
|
|
425
|
+
return new Uint32Array(decodedData);
|
|
448
426
|
}
|
|
449
|
-
export function
|
|
427
|
+
export function decodeZigZagRleDeltaInt32(data, numRuns, numTotalValues) {
|
|
450
428
|
const decodedValues = new Int32Array(numTotalValues + 1);
|
|
451
429
|
decodedValues[0] = 0;
|
|
452
430
|
let offset = 1;
|
|
@@ -454,16 +432,16 @@ export function zigZagRleDeltaDecoding(data, numRuns, numTotalValues) {
|
|
|
454
432
|
for (let i = 0; i < numRuns; i++) {
|
|
455
433
|
const runLength = data[i];
|
|
456
434
|
let value = data[i + numRuns];
|
|
457
|
-
value = (value
|
|
435
|
+
value = decodeZigZagInt32Value(value);
|
|
458
436
|
for (let j = offset; j < offset + runLength; j++) {
|
|
459
437
|
decodedValues[j] = value + previousValue;
|
|
460
438
|
previousValue = decodedValues[j];
|
|
461
439
|
}
|
|
462
440
|
offset += runLength;
|
|
463
441
|
}
|
|
464
|
-
return decodedValues;
|
|
442
|
+
return new Uint32Array(decodedValues);
|
|
465
443
|
}
|
|
466
|
-
export function
|
|
444
|
+
export function decodeRleDeltaInt32(data, numRuns, numTotalValues) {
|
|
467
445
|
const decodedValues = new Int32Array(numTotalValues + 1);
|
|
468
446
|
decodedValues[0] = 0;
|
|
469
447
|
let offset = 1;
|
|
@@ -477,151 +455,8 @@ export function rleDeltaDecoding(data, numRuns, numTotalValues) {
|
|
|
477
455
|
}
|
|
478
456
|
offset += runLength;
|
|
479
457
|
}
|
|
480
|
-
return decodedValues;
|
|
481
|
-
}
|
|
482
|
-
export function padWithZeros(bitVector, data) {
|
|
483
|
-
const decodedData = new Int32Array(bitVector.size());
|
|
484
|
-
let dataCounter = 0;
|
|
485
|
-
let i = 0;
|
|
486
|
-
for (; i != decodedData.length; ++i) {
|
|
487
|
-
decodedData[i] = bitVector.get(i) ? data[dataCounter++] : 0;
|
|
488
|
-
}
|
|
489
|
-
return decodedData;
|
|
490
|
-
}
|
|
491
|
-
export function padZigZagWithZeros(bitVector, data) {
|
|
492
|
-
const decodedData = new Int32Array(bitVector.size());
|
|
493
|
-
let dataCounter = 0;
|
|
494
|
-
let i = 0;
|
|
495
|
-
for (; i != decodedData.length; ++i) {
|
|
496
|
-
if (bitVector.get(i)) {
|
|
497
|
-
const value = data[dataCounter++];
|
|
498
|
-
decodedData[i] = (value >>> 1) ^ -(value & 1);
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
decodedData[i] = 0;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return decodedData;
|
|
505
|
-
}
|
|
506
|
-
export function padWithZerosInt64(bitVector, data) {
|
|
507
|
-
const decodedData = new BigInt64Array(bitVector.size());
|
|
508
|
-
let dataCounter = 0;
|
|
509
|
-
let i = 0;
|
|
510
|
-
for (; i != decodedData.length; ++i) {
|
|
511
|
-
decodedData[i] = bitVector.get(i) ? data[dataCounter++] : 0n;
|
|
512
|
-
}
|
|
513
|
-
return decodedData;
|
|
514
|
-
}
|
|
515
|
-
export function padZigZagWithZerosInt64(bitVector, data) {
|
|
516
|
-
const decodedData = new BigInt64Array(bitVector.size());
|
|
517
|
-
let dataCounter = 0;
|
|
518
|
-
let i = 0;
|
|
519
|
-
for (; i != decodedData.length; ++i) {
|
|
520
|
-
if (bitVector.get(i)) {
|
|
521
|
-
const value = data[dataCounter++];
|
|
522
|
-
decodedData[i] = (value >> 1n) ^ -(value & 1n);
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
decodedData[i] = 0n;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
return decodedData;
|
|
529
|
-
}
|
|
530
|
-
export function decodeNullableRle(data, streamMetadata, isSigned, bitVector) {
|
|
531
|
-
const rleMetadata = streamMetadata;
|
|
532
|
-
return isSigned
|
|
533
|
-
? decodeNullableZigZagRle(bitVector, data, rleMetadata.runs)
|
|
534
|
-
: decodeNullableUnsignedRle(bitVector, data, rleMetadata.runs);
|
|
535
|
-
}
|
|
536
|
-
function decodeNullableUnsignedRle(bitVector, data, numRuns) {
|
|
537
|
-
const values = new Int32Array(bitVector.size());
|
|
538
|
-
let offset = 0;
|
|
539
|
-
for (let i = 0; i < numRuns; i++) {
|
|
540
|
-
const runLength = data[i];
|
|
541
|
-
const value = data[i + numRuns];
|
|
542
|
-
for (let j = offset; j < offset + runLength; j++) {
|
|
543
|
-
/* There can be null values in a run */
|
|
544
|
-
if (bitVector.get(j)) {
|
|
545
|
-
values[j] = value;
|
|
546
|
-
}
|
|
547
|
-
else {
|
|
548
|
-
values[j] = 0;
|
|
549
|
-
offset++;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
offset += runLength;
|
|
553
|
-
}
|
|
554
|
-
return values;
|
|
555
|
-
}
|
|
556
|
-
function decodeNullableZigZagRle(bitVector, data, numRuns) {
|
|
557
|
-
const values = new Int32Array(bitVector.size());
|
|
558
|
-
let offset = 0;
|
|
559
|
-
for (let i = 0; i < numRuns; i++) {
|
|
560
|
-
const runLength = data[i];
|
|
561
|
-
let value = data[i + numRuns];
|
|
562
|
-
value = (value >>> 1) ^ -(value & 1);
|
|
563
|
-
for (let j = offset; j < offset + runLength; j++) {
|
|
564
|
-
/* There can be null values in a run */
|
|
565
|
-
if (bitVector.get(j)) {
|
|
566
|
-
values[j] = value;
|
|
567
|
-
}
|
|
568
|
-
else {
|
|
569
|
-
values[j] = 0;
|
|
570
|
-
offset++;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
offset += runLength;
|
|
574
|
-
}
|
|
575
|
-
return values;
|
|
576
|
-
}
|
|
577
|
-
export function decodeNullableRleInt64(data, streamMetadata, isSigned, bitVector) {
|
|
578
|
-
const rleMetadata = streamMetadata;
|
|
579
|
-
return isSigned
|
|
580
|
-
? decodeNullableZigZagRleInt64(bitVector, data, rleMetadata.runs)
|
|
581
|
-
: decodeNullableUnsignedRleInt64(bitVector, data, rleMetadata.runs);
|
|
582
|
-
}
|
|
583
|
-
function decodeNullableUnsignedRleInt64(bitVector, data, numRuns) {
|
|
584
|
-
const values = new BigInt64Array(bitVector.size());
|
|
585
|
-
let offset = 0;
|
|
586
|
-
for (let i = 0; i < numRuns; i++) {
|
|
587
|
-
const runLength = Number(data[i]);
|
|
588
|
-
const value = data[i + numRuns];
|
|
589
|
-
for (let j = offset; j < offset + runLength; j++) {
|
|
590
|
-
/* There can be null values in a run */
|
|
591
|
-
if (bitVector.get(j)) {
|
|
592
|
-
values[j] = value;
|
|
593
|
-
}
|
|
594
|
-
else {
|
|
595
|
-
values[j] = 0n;
|
|
596
|
-
offset++;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
offset += runLength;
|
|
600
|
-
}
|
|
601
|
-
return values;
|
|
602
|
-
}
|
|
603
|
-
function decodeNullableZigZagRleInt64(bitVector, data, numRuns) {
|
|
604
|
-
const values = new BigInt64Array(bitVector.size());
|
|
605
|
-
let offset = 0;
|
|
606
|
-
for (let i = 0; i < numRuns; i++) {
|
|
607
|
-
const runLength = Number(data[i]);
|
|
608
|
-
let value = data[i + numRuns];
|
|
609
|
-
value = (value >> 1n) ^ -(value & 1n);
|
|
610
|
-
for (let j = offset; j < offset + runLength; j++) {
|
|
611
|
-
/* There can be null values in a run */
|
|
612
|
-
if (bitVector.get(j)) {
|
|
613
|
-
values[j] = value;
|
|
614
|
-
}
|
|
615
|
-
else {
|
|
616
|
-
values[j] = 0n;
|
|
617
|
-
offset++;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
offset += runLength;
|
|
621
|
-
}
|
|
622
|
-
return values;
|
|
458
|
+
return new Uint32Array(decodedValues);
|
|
623
459
|
}
|
|
624
|
-
/* Logical Level Techniques Const and Sequence Vectors ------------------------------------------------------------- */
|
|
625
460
|
/**
|
|
626
461
|
* Decode Delta-RLE with multiple runs by fully reconstructing values.
|
|
627
462
|
*
|
|
@@ -630,14 +465,14 @@ function decodeNullableZigZagRleInt64(bitVector, data, numRuns) {
|
|
|
630
465
|
* @param numValues Total number of values to reconstruct
|
|
631
466
|
* @returns Reconstructed values with deltas applied
|
|
632
467
|
*/
|
|
633
|
-
export function
|
|
468
|
+
export function decodeDeltaRleInt32(data, numRuns, numValues) {
|
|
634
469
|
const result = new Int32Array(numValues);
|
|
635
470
|
let outPos = 0;
|
|
636
471
|
let previousValue = 0;
|
|
637
472
|
for (let i = 0; i < numRuns; i++) {
|
|
638
473
|
const runLength = data[i];
|
|
639
474
|
const zigZagDelta = data[i + numRuns];
|
|
640
|
-
const delta =
|
|
475
|
+
const delta = decodeZigZagInt32Value(zigZagDelta);
|
|
641
476
|
for (let j = 0; j < runLength; j++) {
|
|
642
477
|
previousValue += delta;
|
|
643
478
|
result[outPos++] = previousValue;
|
|
@@ -655,7 +490,7 @@ export function decodeDeltaRleInt64(data, numRuns, numValues) {
|
|
|
655
490
|
for (let i = 0; i < numRuns; i++) {
|
|
656
491
|
const runLength = Number(data[i]);
|
|
657
492
|
const zigZagDelta = data[i + numRuns];
|
|
658
|
-
const delta =
|
|
493
|
+
const delta = decodeZigZagInt64Value(zigZagDelta);
|
|
659
494
|
for (let j = 0; j < runLength; j++) {
|
|
660
495
|
previousValue += delta;
|
|
661
496
|
result[outPos++] = previousValue;
|
|
@@ -663,38 +498,38 @@ export function decodeDeltaRleInt64(data, numRuns, numValues) {
|
|
|
663
498
|
}
|
|
664
499
|
return result;
|
|
665
500
|
}
|
|
666
|
-
export function
|
|
501
|
+
export function decodeUnsignedConstRleInt32(data) {
|
|
667
502
|
return data[1];
|
|
668
503
|
}
|
|
669
|
-
export function
|
|
670
|
-
return
|
|
504
|
+
export function decodeZigZagConstRleInt32(data) {
|
|
505
|
+
return decodeZigZagInt32Value(data[1]);
|
|
671
506
|
}
|
|
672
|
-
export function
|
|
507
|
+
export function decodeZigZagSequenceRleInt32(data) {
|
|
673
508
|
/* base value and delta value are equal */
|
|
674
509
|
if (data.length == 2) {
|
|
675
|
-
const value =
|
|
510
|
+
const value = decodeZigZagInt32Value(data[1]);
|
|
676
511
|
return [value, value];
|
|
677
512
|
}
|
|
678
513
|
/* base value and delta value are not equal -> 2 runs and 2 values*/
|
|
679
|
-
const base =
|
|
680
|
-
const delta =
|
|
514
|
+
const base = decodeZigZagInt32Value(data[2]);
|
|
515
|
+
const delta = decodeZigZagInt32Value(data[3]);
|
|
681
516
|
return [base, delta];
|
|
682
517
|
}
|
|
683
518
|
export function decodeUnsignedConstRleInt64(data) {
|
|
684
519
|
return data[1];
|
|
685
520
|
}
|
|
686
521
|
export function decodeZigZagConstRleInt64(data) {
|
|
687
|
-
return
|
|
522
|
+
return decodeZigZagInt64Value(data[1]);
|
|
688
523
|
}
|
|
689
524
|
export function decodeZigZagSequenceRleInt64(data) {
|
|
690
525
|
/* base value and delta value are equal */
|
|
691
526
|
if (data.length == 2) {
|
|
692
|
-
const value =
|
|
527
|
+
const value = decodeZigZagInt64Value(data[1]);
|
|
693
528
|
return [value, value];
|
|
694
529
|
}
|
|
695
530
|
/* base value and delta value are not equal -> 2 runs and 2 values*/
|
|
696
|
-
const base =
|
|
697
|
-
const delta =
|
|
531
|
+
const base = decodeZigZagInt64Value(data[2]);
|
|
532
|
+
const delta = decodeZigZagInt64Value(data[3]);
|
|
698
533
|
return [base, delta];
|
|
699
534
|
}
|
|
700
535
|
//# sourceMappingURL=integerDecodingUtils.js.map
|