WriteTo writes a serialized version of this bitmap to stream. The format is compatible with other 64-bit RoaringBitmap implementations (Java, Go, C++) and it has a specification : https://github.com/RoaringBitmap/RoaringFormatSpec#extention-for-64-bit-implementations
(stream io.Writer)
| 53 | // implementations (Java, Go, C++) and it has a specification : |
| 54 | // https://github.com/RoaringBitmap/RoaringFormatSpec#extention-for-64-bit-implementations |
| 55 | func (rb *Bitmap) WriteTo(stream io.Writer) (int64, error) { |
| 56 | var n int64 |
| 57 | buf := make([]byte, 8) |
| 58 | binary.LittleEndian.PutUint64(buf, uint64(rb.highlowcontainer.size())) |
| 59 | written, err := stream.Write(buf) |
| 60 | if err != nil { |
| 61 | return n, err |
| 62 | } |
| 63 | n += int64(written) |
| 64 | pos := 0 |
| 65 | keyBuf := buf[:4] |
| 66 | for pos < rb.highlowcontainer.size() { |
| 67 | c := rb.highlowcontainer.getContainerAtIndex(pos) |
| 68 | binary.LittleEndian.PutUint32(keyBuf, rb.highlowcontainer.getKeyAtIndex(pos)) |
| 69 | pos++ |
| 70 | written, err = stream.Write(keyBuf) |
| 71 | n += int64(written) |
| 72 | if err != nil { |
| 73 | return n, err |
| 74 | } |
| 75 | written, err := c.WriteTo(stream) |
| 76 | n += written |
| 77 | if err != nil { |
| 78 | return n, err |
| 79 | } |
| 80 | } |
| 81 | return n, nil |
| 82 | } |
| 83 | |
| 84 | // FromUnsafeBytes reads a serialized version of this bitmap from the byte buffer without copy. |
| 85 | // 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. |