@@ -157,15 +157,83 @@ export enum SerializationFormat {
157
157
*
158
158
*/
159
159
unsafe_frozen_croaring = "unsafe_frozen_croaring" ,
160
+
161
+ /**
162
+ * A plain binary array of 32 bits integers in little endian format. 4 bytes per value.
163
+ */
164
+ uint32_array = "uint32_array" ,
165
+ }
166
+
167
+ export enum FileSerializationFormat {
168
+ /**
169
+ * Stable Optimized non portable C/C++ format. Used by croaring. Can be smaller than the portable format.
170
+ */
171
+ croaring = "croaring" ,
172
+
173
+ /**
174
+ * Stable Portable Java and Go format.
175
+ */
176
+ portable = "unsafe_portable" ,
177
+
178
+ /**
179
+ * A plain binary array of 32 bits integers in little endian format. 4 bytes per value.
180
+ */
181
+ uint32_array = "uint32_array" ,
182
+
183
+ /**
184
+ * Non portable C/C++ frozen format.
185
+ * Is considered unsafe and unstable because the format might change at any new version.
186
+ * Can be useful for temporary storage or for sending data over the network between similar machines.
187
+ * If the content is corrupted when deserialized or when a frozen view is create, the behavior is undefined!
188
+ * The application may crash, buffer overrun, could be a vector of attack!
189
+ *
190
+ * When this option is used in the serialize function, the new returned buffer (if no buffer was provided) will be aligned to a 32 bytes boundary.
191
+ * This is required to create a frozen view with the method unsafeFrozenView.
192
+ *
193
+ */
194
+ unsafe_frozen_croaring = "unsafe_frozen_croaring" ,
195
+
196
+ /**
197
+ * Comma separated values, all values are in decimal and in one line without spaces or other characters.
198
+ */
199
+ comma_separated_values = "comma_separated_values" ,
200
+
201
+ /**
202
+ * Tab "\t" separated values, all values are in decimal and in one line without other characters.
203
+ */
204
+ tab_separated_values = "tab_separated_values" ,
205
+
206
+ /**
207
+ * Newline (\n) separated values, all values are in decimal and one per line with a terminating newline.
208
+ */
209
+ newline_separated_values = "newline_separated_values" ,
210
+
211
+ /**
212
+ * A JSON file in the format "[1,2,3,4...]"
213
+ */
214
+ json_array = "json_array" ,
160
215
}
161
216
162
217
export type SerializationFormatType =
163
218
| SerializationFormat
164
219
| "croaring"
165
220
| "portable"
166
221
| "unsafe_frozen_croaring"
222
+ | "uint32_array"
167
223
| boolean ;
168
224
225
+ export type FileSerializationFormatType =
226
+ | SerializationFormatType
227
+ | FileSerializationFormat
228
+ | "comma_separated_values"
229
+ | "tab_separated_values"
230
+ | "newline_separated_values"
231
+ | "json_array" ;
232
+
233
+ export type SerializationDeserializationFormatType = SerializationFormatType & DeserializationFormatType ;
234
+
235
+ export type FileSerializationDeserializationFormatType = FileSerializationFormatType & FileDeserializationFormatType ;
236
+
169
237
export enum DeserializationFormat {
170
238
/** Stable Optimized non portable C/C++ format. Used by croaring. Can be smaller than the portable format. */
171
239
croaring = "croaring" ,
@@ -190,16 +258,69 @@ export enum DeserializationFormat {
190
258
* The application may crash, buffer overrun, could be a vector of attack!
191
259
*/
192
260
unsafe_frozen_portable = "unsafe_frozen_portable" ,
261
+
262
+ /**
263
+ * A plain binary array of 32 bits integers in little endian format. 4 bytes per value.
264
+ */
265
+ uint32_array = "uint32_array" ,
266
+
267
+ comma_separated_values = "comma_separated_values" ,
268
+ tab_separated_values = "tab_separated_values" ,
269
+ newline_separated_values = "newline_separated_values" ,
270
+ json_array = "json_array" ,
193
271
}
194
272
195
273
export type DeserializationFormatType =
196
- | SerializationFormat
274
+ | DeserializationFormat
197
275
| "croaring"
198
276
| "portable"
199
277
| "unsafe_frozen_croaring"
200
278
| "unsafe_frozen_portable"
279
+ | "uint32_array"
280
+ | "comma_separated_values"
281
+ | "tab_separated_values"
282
+ | "newline_separated_values"
283
+ | "json_array"
201
284
| boolean ;
202
285
286
+ export enum FileDeserializationFormat {
287
+ /** Stable Optimized non portable C/C++ format. Used by croaring. Can be smaller than the portable format. */
288
+ croaring = "croaring" ,
289
+
290
+ /** Stable Portable Java and Go format. */
291
+ portable = "portable" ,
292
+
293
+ /**
294
+ * Non portable C/C++ frozen format.
295
+ * Is considered unsafe and unstable because the format might change at any new version.
296
+ * Can be useful for temporary storage or for sending data over the network between similar machines.
297
+ * If the content is corrupted when loaded or the buffer is modified when a frozen view is create, the behavior is undefined!
298
+ * The application may crash, buffer overrun, could be a vector of attack!
299
+ */
300
+ unsafe_frozen_croaring = "unsafe_frozen_croaring" ,
301
+
302
+ /**
303
+ * Portable version of the frozen view, compatible with Go and Java.
304
+ * Is considered unsafe and unstable because the format might change at any new version.
305
+ * Can be useful for temporary storage or for sending data over the network between similar machines.
306
+ * If the content is corrupted when loaded or the buffer is modified when a frozen view is create, the behavior is undefined!
307
+ * The application may crash, buffer overrun, could be a vector of attack!
308
+ */
309
+ unsafe_frozen_portable = "unsafe_frozen_portable" ,
310
+
311
+ /**
312
+ * A plain binary array of 32 bits integers in little endian format. 4 bytes per value.
313
+ */
314
+ uint32_array = "uint32_array" ,
315
+
316
+ comma_separated_values = "comma_separated_values" ,
317
+ tab_separated_values = "tab_separated_values" ,
318
+ newline_separated_values = "newline_separated_values" ,
319
+ json_array = "json_array" ,
320
+ }
321
+
322
+ export type FileDeserializationFormatType = DeserializationFormatType | FileDeserializationFormat ;
323
+
203
324
export enum FrozenViewFormat {
204
325
/**
205
326
* Non portable C/C++ frozen format.
@@ -1006,6 +1127,18 @@ export interface ReadonlyRoaringBitmap32 extends ReadonlySet<number> {
1006
1127
format : SerializationFormatType ,
1007
1128
) : Promise < Buffer > ;
1008
1129
1130
+ /**
1131
+ * Serializes the bitmap into a file, asynchronously.
1132
+ * The bitmap will be temporarily frozen until the operation completes.
1133
+ *
1134
+ * This is faster, everything runs in its own thread and it consumes less memory than serializing to a Buffer and then to write to a file,
1135
+ * internally it uses memory mapped files and skip all the JS overhead.
1136
+ *
1137
+ * @param {FileSerializationFormat | boolean } format One of the SerializationFormat enum values, or a boolean value: if false, optimized C/C++ format is used. If true, Java and Go portable format is used.
1138
+ * @memberof ReadonlyRoaringBitmap32
1139
+ */
1140
+ serializeFileAsync ( filePath : string , format : FileSerializationFormatType ) : Promise < void > ;
1141
+
1009
1142
/**
1010
1143
* Returns a new ReadonlyRoaringBitmap32 that is a copy of this bitmap, same as new ReadonlyRoaringBitmap32(copy)
1011
1144
*
@@ -1174,7 +1307,6 @@ export interface RoaringBitmap32 extends ReadonlyRoaringBitmap32, Set<number> {
1174
1307
* Overwrite the content of this bitmap copying it from an Iterable or another RoaringBitmap32.
1175
1308
*
1176
1309
* Is faster to pass a Uint32Array instance instead of an array or an iterable.
1177
- *
1178
1310
* Is even faster if a RoaringBitmap32 instance is used (it performs a simple copy).
1179
1311
*
1180
1312
* @param {Iterable<number> } values The new values or a RoaringBitmap32 instance.
@@ -1476,9 +1608,17 @@ export class RoaringBitmap32 {
1476
1608
1477
1609
public readonly SerializationFormat : typeof SerializationFormat ;
1478
1610
1479
- public static readonly DeserializationFormat : typeof SerializationFormat ;
1611
+ public static readonly FileSerializationFormat : typeof FileSerializationFormat ;
1612
+
1613
+ public readonly FileSerializationFormat : typeof FileSerializationFormat ;
1614
+
1615
+ public static readonly FileDeserializationFormat : typeof FileDeserializationFormat ;
1480
1616
1481
- public readonly DeserializationFormat : typeof SerializationFormat ;
1617
+ public readonly FileDeserializationFormat : typeof FileDeserializationFormat ;
1618
+
1619
+ public static readonly DeserializationFormat : typeof DeserializationFormat ;
1620
+
1621
+ public readonly DeserializationFormat : typeof DeserializationFormat ;
1482
1622
1483
1623
public static readonly FrozenViewFormat : typeof FrozenViewFormat ;
1484
1624
@@ -1735,12 +1875,10 @@ export class RoaringBitmap32 {
1735
1875
*
1736
1876
* Returns a Promise that resolves to a new RoaringBitmap32 instance.
1737
1877
*
1738
- * Setting the portable flag to false enable a custom format that can save space compared to the portable format (e.g., for very sparse bitmaps).
1739
1878
* The portable version is meant to be compatible with Java and Go versions.
1879
+ * The croaring version is compatible with the C version, it can be smaller than the portable version.
1740
1880
* When a frozen format is used, the buffer will be copied and the bitmap will be frozen.
1741
1881
*
1742
- * NOTE: portable argument was optional before, now is required and an Error is thrown if the portable flag is not passed.
1743
- *
1744
1882
* @static
1745
1883
* @param {Uint8Array | Uint8ClampedArray | Int8Array | ArrayBuffer| SharedArrayBuffer | null | undefined } serialized An Uint8Array or a node Buffer that contains the serialized data.
1746
1884
* @param {DeserializationFormatType } format The format of the serialized data. true means "portable". false means "croaring".
@@ -1758,12 +1896,10 @@ export class RoaringBitmap32 {
1758
1896
*
1759
1897
* When deserialization is completed or failed, the given callback will be executed.
1760
1898
*
1761
- * Setting the portable flag to false enable a custom format that can save space compared to the portable format (e.g., for very sparse bitmaps).
1762
1899
* The portable version is meant to be compatible with Java and Go versions.
1900
+ * The croaring version is compatible with the C version, it can be smaller than the portable version.
1763
1901
* When a frozen format is used, the buffer will be copied and the bitmap will be frozen.
1764
1902
*
1765
- * NOTE: portable argument was optional before, now is required and an Error is thrown if the portable flag is not passed.
1766
- *
1767
1903
* @static
1768
1904
* @param {Uint8Array | Uint8ClampedArray | Int8Array | ArrayBuffer| SharedArrayBuffer | null | undefined } serialized An Uint8Array or a node Buffer that contains the.
1769
1905
* @param {DeserializationFormatType } format The format of the serialized data. true means "portable". false means "croaring".
@@ -1777,6 +1913,25 @@ export class RoaringBitmap32 {
1777
1913
callback : RoaringBitmap32Callback ,
1778
1914
) : void ;
1779
1915
1916
+ /**
1917
+ * Deserializes the bitmap from a file asynchronously.
1918
+ * Returns a new RoaringBitmap32 instance.
1919
+ *
1920
+ * The portable version is meant to be compatible with Java and Go versions.
1921
+ * The croaring version is compatible with the C version, it can be smaller than the portable version.
1922
+ * When a frozen format is used, the buffer will be copied and the bitmap will be frozen.
1923
+ *
1924
+ * This is faster, everything runs in its own thread and it consumes less memory than serializing to a Buffer and then to write to a file,
1925
+ * internally it uses memory mapped files and skip all the JS overhead.
1926
+ *
1927
+ * @static
1928
+ * @param {string } filePath The path of the file to read.
1929
+ * @param {FileDeserializationFormatType } format The format of the serialized data. true means "portable". false means "croaring".
1930
+ * @returns {Promise<RoaringBitmap32> } A promise that resolves to a new RoaringBitmap32 instance.
1931
+ * @memberof RoaringBitmap32
1932
+ */
1933
+ public static deserializeFileAsync ( filePath : string , format : FileDeserializationFormatType ) : Promise < RoaringBitmap32 > ;
1934
+
1780
1935
/**
1781
1936
*
1782
1937
* Deserializes many bitmaps from an array of Uint8Array or an array of Buffer asynchronously in multiple parallel threads.
0 commit comments