@@ -277,26 +277,34 @@ func (rb *Bitmap) Checksum() uint64 {
277
277
return hash
278
278
}
279
279
280
- // FromUnsafeBytes reads a serialized version of this bitmap from the byte buffer without copy.
280
+ // FromUnsafeBytes reads a serialized version of this bitmap from the byte buffer without copy
281
+ // (for advanced users only, you must be an expert Go programmer!).
282
+ // E.g., you can use this method to read a serialized bitmap from a memory-mapped file written out
283
+ // with the WriteTo method.
284
+ // The format specification is
285
+ // https://github.com/RoaringBitmap/RoaringFormatSpec
281
286
// It is the caller's responsibility to ensure that the input data is not modified and remains valid for the entire lifetime of this bitmap.
282
287
// This method avoids small allocations but holds references to the input data buffer. It is GC-friendly, but it may consume more memory eventually.
283
288
// The containers in the resulting bitmap are immutable containers tied to the provided byte array and they rely on
284
289
// copy-on-write which means that modifying them creates copies. Thus FromUnsafeBytes is more likely to be appropriate for read-only use cases,
285
290
// when the resulting bitmap can be considered immutable.
286
291
//
287
- // See also the FromBuffer function.
292
+ // See also the FromBuffer function: most users should prefer FromBuffer unless the need the performance,
293
+ // and are aware of the implications of holding references to the input data buffer.
288
294
// See https://github.com/RoaringBitmap/roaring/pull/395 for more details.
289
295
func (rb * Bitmap ) FromUnsafeBytes (data []byte , cookieHeader ... byte ) (p int64 , err error ) {
290
296
stream := internal .NewByteBuffer (data )
291
297
return rb .ReadFrom (stream )
292
298
}
293
299
294
300
// ReadFrom reads a serialized version of this bitmap from stream.
301
+ // E.g., you can use this method to read a serialized bitmap from a file written
302
+ // with the WriteTo method.
295
303
// The format is compatible with other RoaringBitmap
296
304
// implementations (Java, C) and is documented here:
297
305
// https://github.com/RoaringBitmap/RoaringFormatSpec
298
- // Since io.Reader is regarded as a stream and cannot be read twice.
299
- // So add cookieHeader to accept the 4-byte data that has been read in roaring64.ReadFrom.
306
+ // Since io.Reader is regarded as a stream and cannot be read twice,
307
+ // we add cookieHeader to accept the 4-byte data that has been read in roaring64.ReadFrom.
300
308
// It is not necessary to pass cookieHeader when call roaring.ReadFrom to read the roaring32 data directly.
301
309
func (rb * Bitmap ) ReadFrom (reader io.Reader , cookieHeader ... byte ) (p int64 , err error ) {
302
310
stream , ok := reader .(internal.ByteInput )
@@ -325,7 +333,7 @@ func (rb *Bitmap) MustReadFrom(reader io.Reader, cookieHeader ...byte) (p int64,
325
333
return
326
334
}
327
335
328
- // FromBuffer creates a bitmap from its serialized version stored in buffer
336
+ // FromBuffer creates a bitmap from its serialized version stored in buffer (E.g., as written by WriteTo).
329
337
//
330
338
// The format specification is available here:
331
339
// https://github.com/RoaringBitmap/RoaringFormatSpec
0 commit comments