aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/RoaringBitmap/roaring/serialization_generic.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/RoaringBitmap/roaring/serialization_generic.go')
-rw-r--r--vendor/github.com/RoaringBitmap/roaring/serialization_generic.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/vendor/github.com/RoaringBitmap/roaring/serialization_generic.go b/vendor/github.com/RoaringBitmap/roaring/serialization_generic.go
index 7fcef7691b..4b9d9e3d48 100644
--- a/vendor/github.com/RoaringBitmap/roaring/serialization_generic.go
+++ b/vendor/github.com/RoaringBitmap/roaring/serialization_generic.go
@@ -4,6 +4,7 @@ package roaring
import (
"encoding/binary"
+ "errors"
"io"
)
@@ -26,6 +27,10 @@ func (b *arrayContainer) readFrom(stream io.Reader) (int, error) {
}
func (b *bitmapContainer) writeTo(stream io.Writer) (int, error) {
+ if b.cardinality <= arrayDefaultMaxSize {
+ return 0, errors.New("refusing to write bitmap container with cardinality of array container")
+ }
+
// Write set
buf := make([]byte, 8*len(b.bitmap))
for i, v := range b.bitmap {
@@ -69,6 +74,16 @@ func uint64SliceAsByteSlice(slice []uint64) []byte {
return by
}
+func uint16SliceAsByteSlice(slice []uint16) []byte {
+ by := make([]byte, len(slice)*2)
+
+ for i, v := range slice {
+ binary.LittleEndian.PutUint16(by[i*2:], v)
+ }
+
+ return by
+}
+
func byteSliceAsUint16Slice(slice []byte) []uint16 {
if len(slice)%2 != 0 {
panic("Slice size should be divisible by 2")