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

.

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