ReadFrom reads a serialized version of this bitmap from 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.Reader)
| 131 | // implementations (Java, Go, C++) and it has a specification : |
| 132 | // https://github.com/RoaringBitmap/RoaringFormatSpec#extention-for-64-bit-implementations |
| 133 | func (rb *Bitmap) ReadFrom(stream io.Reader) (p int64, err error) { |
| 134 | sizeBuf := make([]byte, 8) |
| 135 | var n int |
| 136 | n, err = io.ReadFull(stream, sizeBuf) |
| 137 | if err != nil { |
| 138 | return int64(n), err |
| 139 | } |
| 140 | p += int64(n) |
| 141 | size := binary.LittleEndian.Uint64(sizeBuf) |
| 142 | rb.highlowcontainer.resize(0) |
| 143 | if cap(rb.highlowcontainer.keys) >= int(size) { |
| 144 | rb.highlowcontainer.keys = rb.highlowcontainer.keys[:size] |
| 145 | } else { |
| 146 | rb.highlowcontainer.keys = make([]uint32, size) |
| 147 | } |
| 148 | if cap(rb.highlowcontainer.containers) >= int(size) { |
| 149 | rb.highlowcontainer.containers = rb.highlowcontainer.containers[:size] |
| 150 | } else { |
| 151 | rb.highlowcontainer.containers = make([]*roaring.Bitmap, size) |
| 152 | } |
| 153 | if cap(rb.highlowcontainer.needCopyOnWrite) >= int(size) { |
| 154 | rb.highlowcontainer.needCopyOnWrite = rb.highlowcontainer.needCopyOnWrite[:size] |
| 155 | } else { |
| 156 | rb.highlowcontainer.needCopyOnWrite = make([]bool, size) |
| 157 | } |
| 158 | keyBuf := sizeBuf[:4] |
| 159 | for i := uint64(0); i < size; i++ { |
| 160 | n, err = io.ReadFull(stream, keyBuf) |
| 161 | if err != nil { |
| 162 | return int64(n), fmt.Errorf("error in bitmap.readFrom: could not read key #%d: %s", i, err) |
| 163 | } |
| 164 | p += int64(n) |
| 165 | rb.highlowcontainer.keys[i] = binary.LittleEndian.Uint32(keyBuf) |
| 166 | rb.highlowcontainer.containers[i] = roaring.NewBitmap() |
| 167 | n, err := rb.highlowcontainer.containers[i].ReadFrom(stream) |
| 168 | |
| 169 | if n == 0 || err != nil { |
| 170 | return n, fmt.Errorf("Could not deserialize bitmap for key #%d: %s", i, err) |
| 171 | } |
| 172 | p += n |
| 173 | } |
| 174 | return p, nil |
| 175 | } |
| 176 | |
| 177 | // MarshalBinary implements the encoding.BinaryMarshaler interface for the bitmap |
| 178 | // (same as ToBytes) |