diff --git a/sparsevec.go b/sparsevec.go index f390e48..9b86e52 100644 --- a/sparsevec.go +++ b/sparsevec.go @@ -153,15 +153,16 @@ func (v *SparseVector) DecodeBinary(buf []byte) error { v.dim = int32(dim) v.indices = make([]int32, 0, nnz) v.values = make([]float32, 0, nnz) + offset := 12 for i := 0; i < nnz; i++ { - offset := 12 + 4*i v.indices = append(v.indices, int32(binary.BigEndian.Uint32(buf[offset:offset+4]))) + offset += 4 } for i := 0; i < nnz; i++ { - offset := 12 + 4*nnz + 4*i v.values = append(v.values, math.Float32frombits(binary.BigEndian.Uint32(buf[offset:offset+4]))) + offset += 4 } return nil diff --git a/vector.go b/vector.go index 44b8d9c..175b793 100644 --- a/vector.go +++ b/vector.go @@ -78,9 +78,10 @@ func (v *Vector) DecodeBinary(buf []byte) error { } v.vec = make([]float32, 0, dim) + offset := 4 for i := 0; i < dim; i++ { - offset := 4 + 4*i v.vec = append(v.vec, math.Float32frombits(binary.BigEndian.Uint32(buf[offset:offset+4]))) + offset += 4 } return nil }