bits-and-blooms/bitset

Marshall functions should consider `length` instead of writing whole `set`

omerfirmak opened this issue · 1 comments

Due to calls like Delete(), size of set and length could be out of sync.

Whole b.set is marshaled;

	for i := range b.set {
		binaryOrder.PutUint64(item, b.set[i])
		if nn, err := writer.Write(item); err != nil {
			return int64(i*binary.Size(uint64(0)) + nn), err
		}
	}

but only nWords amount of uint64 is unmarshaled

	nWords := wordsNeeded(uint(length))
	reader := bufio.NewReader(io.LimitReader(stream, 8*int64(nWords)))
	for i := 0; i < nWords; i++ {
		if _, err := io.ReadFull(reader, item[:]); err != nil {
			if err == io.EOF {
				err = io.ErrUnexpectedEOF
			}
			return 0, err
		}
		newset.set[i] = binaryOrder.Uint64(item[:])
	}

this results in UnmarshalBinary consuming only part of the data emitted by MarshalBinary
the remaning part causes all sorts of uncertainty in the deserialization process of complex data structures.

WriteTo should consider b.length to decide how many words it should marshal

Yes. Pull request invited.