Commit 52972b18 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 99cc03b5
...@@ -242,6 +242,8 @@ type nodeTrack struct { ...@@ -242,6 +242,8 @@ type nodeTrack struct {
// δtrackIndex represents change to trackIndex. XXX name // δtrackIndex represents change to trackIndex. XXX name
// //
// XXX refer to trackIndex.ApplyΔ
//
// The result B of applying δ to A is: // The result B of applying δ to A is:
// //
// B = A.xDifference(δ.Del).xUnion(δ.Add) (*) // B = A.xDifference(δ.Del).xUnion(δ.Add) (*)
...@@ -368,6 +370,11 @@ func (A trackIndex) DifferenceInplace(B trackIndex) { ...@@ -368,6 +370,11 @@ func (A trackIndex) DifferenceInplace(B trackIndex) {
δnchild := map[zodb.Oid]int{} δnchild := map[zodb.Oid]int{}
A.xDifferenceInplace(B, δnchild)
A.fixup(δnchild)
}
func (A trackIndex) xDifferenceInplace(B trackIndex, δ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 {
if t2.nchild != 0 { if t2.nchild != 0 {
...@@ -386,18 +393,19 @@ func (A trackIndex) DifferenceInplace(B trackIndex) { ...@@ -386,18 +393,19 @@ func (A trackIndex) DifferenceInplace(B trackIndex) {
δnchild[t.parent] -= 1 δnchild[t.parent] -= 1
} }
} }
}
/* XXX kill func (A trackIndex) xUnionInplace(B trackIndex, δnchild map[zodb.Oid]int) {
// process adds // process additions
for oid, δt := range δ.Add { for oid, t2 := range B {
t, already := A[oid] t, already := A[oid]
if already { if already {
if t.parent != zodb.InvalidOid { if t.parent != zodb.InvalidOid {
δnchild[t.parent] -= 1 δnchild[t.parent] -= 1
t.parent = δt.parent t.parent = t2.parent
} }
} else { } else {
t = &nodeTrack{parent: δt.parent, nchild: 0} t = &nodeTrack{parent: t2.parent, nchild: 0}
A[oid] = t A[oid] = t
} }
...@@ -405,9 +413,11 @@ func (A trackIndex) DifferenceInplace(B trackIndex) { ...@@ -405,9 +413,11 @@ func (A trackIndex) DifferenceInplace(B trackIndex) {
δnchild[t.parent] += 1 // remeber to nchild++ in parent δnchild[t.parent] += 1 // remeber to nchild++ in parent
} }
} }
*/ }
// perform scheduled δnchild adjustment // fixup performs scheduled δnchild adjustment.
// XXX place
func (A trackIndex) fixup(δnchild map[zodb.Oid]int) {
gcq := []zodb.Oid{} gcq := []zodb.Oid{}
for oid, δnc := range δnchild { for oid, δnc := range δnchild {
t := A[oid] // XXX t can be nil -> XXX no must be there as A is connected t := A[oid] // XXX t can be nil -> XXX no must be there as A is connected
...@@ -436,6 +446,10 @@ func (A trackIndex) UnionInplace(B trackIndex) { ...@@ -436,6 +446,10 @@ func (A trackIndex) UnionInplace(B trackIndex) {
B.verify() B.verify()
defer A.verify() defer A.verify()
δnchild := map[zodb.Oid]int{}
A.xUnionInplace(B, δnchild)
A.fixup(δnchild)
/*
for oid, t2 := range B { for oid, t2 := range B {
t, already := A[oid] t, already := A[oid]
if !already { if !already {
...@@ -460,6 +474,7 @@ func (A trackIndex) UnionInplace(B trackIndex) { ...@@ -460,6 +474,7 @@ func (A trackIndex) UnionInplace(B trackIndex) {
} }
} }
} }
*/
} }
// ApplyΔ applies δ to trackIdx. XXX // ApplyΔ applies δ to trackIdx. XXX
...@@ -475,8 +490,12 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) { ...@@ -475,8 +490,12 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
δ.Add.verify() δ.Add.verify()
defer tidx.verify() defer tidx.verify()
tidx.DifferenceInplace(δ.Del) δnchild := map[zodb.Oid]int{}
tidx.UnionInplace(δ.Add)
tidx.xDifferenceInplace(δ.Del, δnchild)
tidx.xUnionInplace(δ.Add, δnchild)
tidx.fixup(δnchild)
} }
// treeSetKey represents ordered set of keys. // treeSetKey represents ordered set of keys.
......
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