func (a *leaf) balanceAt(b *leaf, m int) error { var lim int = int(a.meta.keyCount) - m for i := 0; i < lim; i++ { j := m + i copy(b.val(i), a.val(j)) fmap.MemClr(a.val(j)) copy(b.key(i), a.key(j)) fmap.MemClr(a.key(j)) } b.meta.keyCount = a.meta.keyCount - uint16(m) a.meta.keyCount = uint16(m) return nil }
func (a *internal) balance(v *Varchar, b *internal) error { if b.meta.keyCount != 0 { return errors.Errorf("b was not empty") } m, err := a.balancePoint(v) if err != nil { return err } var lim int = int(a.meta.keyCount) - m for i := 0; i < lim; i++ { j := m + i copy(b.key(i), a.key(j)) fmap.MemClr(a.key(j)) *b.ptr(i) = *a.ptr(j) *a.ptr(j) = 0 } b.meta.keyCount = a.meta.keyCount - uint16(m) a.meta.keyCount = uint16(m) /* err = checkOrder(v, a) if err != nil { log.Println("balance point", m) log.Println(a) return err } err = checkOrder(v, b) if err != nil { log.Println("balance point", m) log.Println(b) return err } */ return nil }
func (n *leaf) delItemAt(v *Varchar, idx int) error { // ok we have our key_idx if idx+1 == int(n.meta.keyCount) { // sweet we can just drop the last // key value n.meta.keyCount-- // zero out the old ones fmap.MemClr(n.key(idx)) fmap.MemClr(n.val(idx)) return nil } chunk := int(n.meta.keyCount) - idx - 1 // drop the key { keys := n.keys() keySize := int(n.meta.keySize) chunkSize := chunk * keySize s := idx * keySize e := s + chunkSize from := keys[s+keySize : e+keySize] to := keys[s:e] copy(to, from) } // drop the value { vals := n.vals() valSize := int(n.meta.valSize) chunkSize := chunk * valSize s := idx * valSize e := s + chunkSize from := vals[s+valSize : e+valSize] to := vals[s:e] copy(to, from) } // do the book keeping n.meta.keyCount-- /* err := checkOrder(v, n) if err != nil { log.Println("del at", idx) log.Println(n) return err } */ return nil }
func (n *internal) delKeyAt(v *Varchar, i int) (err error) { if n.meta.keyCount == 0 { return errors.Errorf("The items slice is empty") } if i < 0 || i >= int(n.meta.keyCount) { return errors.Errorf("i was not in range") } if n.meta.flags&consts.VARCHAR_KEYS != 0 { k := n.key(i) err = v.Deref(*slice.AsUint64(&k)) if err != nil { return err } } for j := i; j+1 < int(n.meta.keyCount); j++ { copy(n.key(j), n.key(j+1)) } // zero the old fmap.MemClr(n.key(int(n.meta.keyCount - 1))) return nil }