Commit 563f3e5e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3ab0c05c
......@@ -269,8 +269,15 @@ type nodeTrack struct {
// The second component with "-22" builds from leaf, but the first
// component with "-43" builds from non-leaf node.
//
// Only complete result of applying both δ.Del and δ.Add produce correctly
// PP-connected set.
// δnchildNonLeafs = {43: +1}
//
// Only complete result of applying all
//
// - δ.Del,
// - δ.Add, and
// - fixup(δnchildNonLeafs)
//
// produce correctly PP-connected set.
//
// XXX place
type δtrackIndex struct {
......@@ -282,8 +289,21 @@ type δtrackIndex struct {
*/
Del trackIndex
Add trackIndex
δnchildNonLeafs map[zodb.Oid]int
}
// Update updates δ to be combination of δ+δ2.
func (δ *δtrackIndex) Update(δ2 *δtrackIndex) {
δ.Del.UnionInplace(δ2.Del)
δ.Add.UnionInplace(δ2.Add)
for oid, δnc := range δ2.δnchildNonLeafs {
δ.δnchildNonLeafs[oid] += δnc
}
}
// XXX Revert
// gc1 garbage-collects oid and cleans up its parent down-up.
func (tidx trackIndex) gc1(oid zodb.Oid) {
t, present := tidx[oid]
......@@ -368,17 +388,23 @@ func (A trackIndex) DifferenceInplace(B trackIndex) {
B.verify()
defer A.verify()
δnchild := map[zodb.Oid]int{}
A.xDifferenceInplace(B, δnchild)
A.fixup(δnchild)
// δnchild := map[zodb.Oid]int{}
A.xDifferenceInplace(B)
// A.fixup(δnchild)
}
func (A trackIndex) xDifferenceInplace(B trackIndex, δnchild map[zodb.Oid]int) {
//func (A trackIndex) xDifferenceInplace(B trackIndex, δnchild map[zodb.Oid]int) {
func (A trackIndex) xDifferenceInplace(B trackIndex) {
fmt.Printf("\n\n xDifferenceInplace:\n")
fmt.Printf(" a: %s\n", A)
fmt.Printf(" b: %s\n", B)
defer fmt.Printf(" ->d: %s\n", A)
// fmt.Printf(" δ: %v\n", δnchild)
defer func() {
fmt.Printf(" ->d: %s\n", A)
// fmt.Printf(" ->δ: %v\n", δnchild)
}()
δnchild := map[zodb.Oid]int{}
// remove B.leafs and thier parents
for oid, t2 := range B {
......@@ -405,13 +431,22 @@ func (A trackIndex) xDifferenceInplace(B trackIndex, δnchild map[zodb.Oid]int)
δnchild[t.parent] -= 1
}
}
A.fixup(δnchild)
}
func (A trackIndex) xUnionInplace(B trackIndex, δnchild map[zodb.Oid]int) {
//func (A trackIndex) xUnionInplace(B trackIndex, δnchild map[zodb.Oid]int) {
func (A trackIndex) xUnionInplace(B trackIndex) {
fmt.Printf("\n\n xUnionInplace:\n")
fmt.Printf(" a: %s\n", A)
fmt.Printf(" b: %s\n", B)
defer fmt.Printf(" ->u: %s\n", A)
// fmt.Printf(" δ: %v\n", δnchild)
defer func() {
fmt.Printf(" ->u: %s\n", A)
// fmt.Printf(" ->δ: %v\n", δnchild)
}()
δnchild := map[zodb.Oid]int{}
for oid, t2 := range B {
t, already := A[oid]
......@@ -433,6 +468,8 @@ func (A trackIndex) xUnionInplace(B trackIndex, δnchild map[zodb.Oid]int) {
}
}
}
A.fixup(δnchild)
}
// fixup performs scheduled δnchild adjustment.
......@@ -466,9 +503,9 @@ func (A trackIndex) UnionInplace(B trackIndex) {
B.verify()
defer A.verify()
δnchild := map[zodb.Oid]int{}
A.xUnionInplace(B, δnchild)
A.fixup(δnchild)
// δnchild := map[zodb.Oid]int{}
A.xUnionInplace(B)
// A.fixup(δnchild)
/*
for oid, t2 := range B {
t, already := A[oid]
......@@ -503,6 +540,7 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
fmt.Printf(" A: %s\n", tidx)
fmt.Printf(" -: %s\n", δ.Del)
fmt.Printf(" +: %s\n", δ.Add)
fmt.Printf(" x: %v\n", δ.δnchildNonLeafs)
defer fmt.Printf("\n->B: %s\n", tidx)
tidx.verify()
......@@ -510,12 +548,9 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
δ.Add.verify()
defer tidx.verify()
δnchild := map[zodb.Oid]int{}
tidx.xDifferenceInplace(δ.Del, δnchild)
tidx.xUnionInplace(δ.Add, δnchild)
tidx.fixup(δnchild)
tidx.xDifferenceInplace(δ.Del)
tidx.xUnionInplace(δ.Add)
tidx.fixup(δ.δnchildNonLeafs)
}
// treeSetKey represents ordered set of keys.
......@@ -1257,10 +1292,9 @@ func treediff(ctx context.Context, root zodb.Oid, δtops SetOid, δZTC SetOid, t
}
}
*/
δtrack := &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}}
δtrack := &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}, δnchildNonLeafs: map[zodb.Oid]int{}}
for _, δ := range δtrackv {
δtrack.Del.UnionInplace(δ.Del)
δtrack.Add.UnionInplace(δ.Add)
δtrack.Update(δ)
}
trackIdx.ApplyΔ(δtrack)
......@@ -1337,7 +1371,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
δ = map[Key]ΔValue{}
// δtrack = &δtrackIndex{DelLeaf: SetOid{}, Add: trackIndex{}}
δtrack = &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}}
δtrack = &δtrackIndex{Del: trackIndex{}, Add: trackIndex{}, δnchildNonLeafs: map[zodb.Oid]int{}}
defer tracef(" -> δ: %v\n", δ)
// path prefix to A and B
......@@ -1430,7 +1464,7 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
achildren := Av.Expand(ra)
for _, ac := range achildren {
acOid := ac.node.POid()
_, tracked := trackIdx[acOid]
at, tracked := trackIdx[acOid]
if !tracked && /*cannot skip embedded bucket:*/acOid != zodb.InvalidOid {
continue
}
......@@ -1479,10 +1513,11 @@ func diffT(ctx context.Context, A, B *Tree, δZTC SetOid, trackIdx trackIndex, h
apath := trackIdx.Path(acOid)
bpath := BtrackIdx.Path(acOid)
if !pathEqual(apath, bpath) {
δtrack.Add.AddPath(bpath)
δtrack.Del.AddPath(apath)
// remove all nodes from under a XXX no
// XXX (a was not changed and nothing under a was changed) -> we just have to correct path till a.
δtrack.Add.AddPath(bpath)
if nc := at.nchild; nc != 0 {
δtrack.δnchildNonLeafs[acOid] = nc
}
}
/* XXX kill
......
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