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

.

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