Fix bug in condensor uin64 slice writing
@@ -110,7 +110,7 @@ func (c *MemoryCondensor2) writeUint64(w *bufWriter, in uint64) error {
func (c *MemoryCondensor2) writeUint16(w *bufWriter, in uint16) error {
toWrite := make([]byte, 2)
- binary.LittleEndian.PutUint16(toWrite, in)
+ binary.LittleEndian.PutUint16(toWrite[0:2], in)
_, err := w.Write(toWrite)
if err != nil {
return err
@@ -130,31 +130,20 @@ func (c *MemoryCondensor2) writeCommitType(w *bufWriter, in HnswCommitType) erro
return nil
}
-func (c *MemoryCondensor2) writeUint64Slice(w *bufWriter, in []uint64) error {
- buf := make([]byte, 8*len(in))
- i := 0
- for i < len(in) {
- if i != 0 && i%8 == 0 {
- if _, err := w.Write(buf); err != nil {
- return err
- }
- }
+// func (c *MemoryCondensor2) writeUint64Slice(w io.Writer, in []uint64) error {
+// err := binary.Write(w, binary.LittleEndian, &in)
+// if err != nil {
+// return errors.Wrap(err, "writing []uint64")
+// }
- pos := i % 8
- start := pos * 8
- end := start + 8
- binary.LittleEndian.PutUint64(buf[start:end], in[i])
- i++
- }
+// return nil
+// }
- if i != 0 {
- start := 0
- end := i % 8 * 8
- if end == 0 {
- end = 64
- }
- if _, err := w.Write(buf[start:end]); err != nil {
+func (c *MemoryCondensor2) writeUint64Slice(w *bufWriter, in []uint64) error {
+ for _, v := range in {
+ err := c.writeUint64(w, v)
+ if err != nil {
return err
}
}
@@ -162,6 +151,7 @@ func (c *MemoryCondensor2) writeUint64Slice(w *bufWriter, in []uint64) error {
return nil
}
+
// AddNode adds an empty node
func (c *MemoryCondensor2) AddNode(node *vertex) error {
ec := &errorCompounder{}
@@ -172,6 +162,8 @@ func (c *MemoryCondensor2) AddNode(node *vertex) error {
return ec.toError()
}
+
+
func (c *MemoryCondensor2) SetLinksAtLevel(nodeid uint64, level int, targets []uint64) error {
ec := &errorCompounder{}
ec.add(c.writeCommitType(c.newLog, ReplaceLinksAtLevel))
