Commit 2db00f78 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c0422b6f
......@@ -412,6 +412,21 @@ func (A trackIndex) xDifferenceInplace(B trackIndex) {
δnchild := map[zodb.Oid]int{}
/* XXX kill
// remove (A^B).leafs and thier parents
// we have to start (A^B).leafs - not from B.leafs - because B can
// contain non-leaf to remove from A, with that non-leaf having
// children in B, that are not present in A:
//
// c c
// | |
// 11 11
// | |
// 14 14
// | \
// 15 16
AB := B.Intersect(A)
*/
// remove B.leafs and thier parents
for oid, t2 := range B {
if t2.nchild != 0 {
......@@ -433,6 +448,7 @@ func (A trackIndex) xDifferenceInplace(B trackIndex) {
}
delete(A, oid)
// XXX + return A.nchild in removedNonLeafs {} oid -> nchild ? (probably no)
if t.parent != zodb.InvalidOid {
δnchild[t.parent] -= 1
}
......@@ -483,10 +499,13 @@ func (A trackIndex) xUnionInplace(B trackIndex) {
// fixup performs scheduled δnchild adjustment.
// XXX place
func (A trackIndex) fixup(δnchild map[zodb.Oid]int) {
A.xfixup(+1, δnchild)
}
func (A trackIndex) xfixup(sign int, δ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
t.nchild += δnc
t.nchild += sign*δnc
if t.nchild == 0 && /* not root node */t.parent != zodb.InvalidOid {
gcq = append(gcq, oid)
}
......@@ -560,9 +579,10 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
δ.Add.verify()
defer tidx.verify()
tidx.xfixup(-1, δ.δnchildNonLeafs)
tidx.xDifferenceInplace(δ.Del)
tidx.xUnionInplace(δ.Add)
tidx.fixup(δ.δnchildNonLeafs)
tidx.xfixup(+1, δ.δnchildNonLeafs)
}
// treeSetKey represents ordered set of keys.
......
......@@ -1430,7 +1430,7 @@ func TestΔBTail(t *testing.T) {
"T2,5/B1:a-B2:b,4:d-B8:h", // XXX add A
// found by AllStructs ([1] is not changed, but because B1 is
// unlinked and 1 migrates to othe bucket, changes in that
// unlinked and 1 migrates to other bucket, changes in that
// other bucket must be included into δT)
"T1,2/B0:e-B1:d-B2:g,3:a",
"T1/B0:d-B1:d,2:d",
......@@ -1485,6 +1485,9 @@ func TestΔBTail(t *testing.T) {
"T/T1/T-T2/B0:e-B1:f-B2:g",
// ApplyΔ -> xunion: node is reachable from multiple parents
// ( because xdifference did not remove common non-leaf node
// under which there were also other changed, but not initially
// tracked, node )
"T4/T1-T/T-T2-B4:c/T-T-T/B0:f-B1:h-B2:g,3:b",
"T1/T-T/T-T2/T-T-T/B0:f-B1:h-B2:f",
// ----//----
......
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