Commit 4a7e9275 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f2dde045
...@@ -347,28 +347,42 @@ func (δBtail *ΔBtail) treediff(ctx context.Context, root zodb.Oid, δZT SetOid ...@@ -347,28 +347,42 @@ func (δBtail *ΔBtail) treediff(ctx context.Context, root zodb.Oid, δZT SetOid
case *Tree: case *Tree:
b := xb.(*Tree) // must not fail b := xb.(*Tree) // must not fail
// TODO handle // TODO handle
_ = b
} }
} }
return nil, nil // XXX stub return nil, nil // XXX stub
} }
// diffB computes difference in between two buckets. // diffB computes difference in between two revisions of a bucket.
// the buckets must be already activated // the buckets must be already activated
func diffB(a, b *Bucket) map[Key]Value { func diffB(a, b *Bucket) (δ map[Key]Value, err error) {
av := a.Entryv() defer xerr.Contextf(&err, "diffB %s", a.POid())
bv := b.Entryv() if a.POid() != b.POid() {
δ := map[Key]Value{} panic("different buckets")
}
av := a.Entryv() // key↑
bv := b.Entryv() // key↑
δ = map[Key]Value{}
for len(av) > 0 || len(bv) > 0 { for len(av) > 0 || len(bv) > 0 {
ka, va := KeyMax, VDEL ka, va := KeyMax, VDEL
kb, vb := KeyMax, VDEL kb, vb := KeyMax, VDEL
if len(av) > 0 { if len(av) > 0 {
ka, va = av[0].Key(), av[0].Value() ka = av[0].Key()
va, err = vOid(av[0].Value())
if err != nil {
return nil, fmt.Errorf("a[%v]: %s", ka, err)
}
} }
if len(bv) > 0 { if len(bv) > 0 {
kb, vb = bv[0].Key(), bv[0].Value() kb = bv[0].Key()
vb, err = vOid(bv[0].Value())
if err != nil {
return nil, fmt.Errorf("b[%v]: %s", kb, err)
}
} }
switch { switch {
...@@ -377,14 +391,28 @@ func diffB(a, b *Bucket) map[Key]Value { ...@@ -377,14 +391,28 @@ func diffB(a, b *Bucket) map[Key]Value {
δ[ka] = VDEL δ[ka] = VDEL
case ka > kb: // +b[0] case ka > kb: // +b[0]
bv = bv[1:]
δ[kb] = vb
// ka == kb // va->vb // ka == kb // va->vb
default: case va != vb:
av = av[1:] av = av[1:]
bv = bv[1:] bv = bv[1:]
δ[ka] = vb δ[ka] = vb
} }
} }
return δ, nil
}
// vOid returns OID of a value object.
// it is an error if value is not persistent object.
func vOid(xvalue interface{}) (zodb.Oid, error) {
value, ok := xvalue.(zodb.IPersistent)
if !ok {
return zodb.InvalidOid, fmt.Errorf("%T is not a persitent object", xvalue)
}
return value.POid(), nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment