Commit 01b98455 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7ed177e4
...@@ -61,6 +61,16 @@ type nodeInTree struct { ...@@ -61,6 +61,16 @@ type nodeInTree struct {
nchild int // number of direct children in PPTreeSubSet referring to this node nchild int // number of direct children in PPTreeSubSet referring to this node
} }
// Parent returns parent of this node.
func (n *nodeInTree) Parent() zodb.Oid {
return n.parent
}
// NChild returns number of children of this node in the tree subset.
func (n *nodeInTree) NChild() int {
return n.nchild
}
// Has returns whether node is in the set. // Has returns whether node is in the set.
func (S PPTreeSubSet) Has(oid zodb.Oid) bool { func (S PPTreeSubSet) Has(oid zodb.Oid) bool {
_, ok := S[oid] _, ok := S[oid]
...@@ -464,20 +474,20 @@ func (t nodeInTree) String() string { ...@@ -464,20 +474,20 @@ func (t nodeInTree) String() string {
// 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.
// //
// δnchildNonLeafs = {43: +1} // ΔnchildNonLeafs = {43: +1}
// //
// Only complete result of applying all // Only complete result of applying all
// //
// - xfixup(-1, δnchildNonLeafs) // - xfixup(-1, ΔnchildNonLeafs)
// - δ.Del, // - δ.Del,
// - δ.Add, and // - δ.Add, and
// - xfixup(+1, δnchildNonLeafs) // - xfixup(+1, ΔnchildNonLeafs)
// //
// produces correctly PP-connected set. // produces correctly PP-connected set.
type ΔPPTreeSubSet struct { type ΔPPTreeSubSet struct {
Del PPTreeSubSet Del PPTreeSubSet
Add PPTreeSubSet Add PPTreeSubSet
δnchildNonLeafs map[zodb.Oid]int ΔnchildNonLeafs map[zodb.Oid]int
} }
// NewΔPPTreeSubSet creates new empty ΔPPTreeSubSet. // NewΔPPTreeSubSet creates new empty ΔPPTreeSubSet.
...@@ -485,7 +495,7 @@ func NewΔPPTreeSubSet() *ΔPPTreeSubSet { ...@@ -485,7 +495,7 @@ func NewΔPPTreeSubSet() *ΔPPTreeSubSet {
return &ΔPPTreeSubSet{ return &ΔPPTreeSubSet{
Del: PPTreeSubSet{}, Del: PPTreeSubSet{},
Add: PPTreeSubSet{}, Add: PPTreeSubSet{},
δnchildNonLeafs: map[zodb.Oid]int{}, ΔnchildNonLeafs: map[zodb.Oid]int{},
} }
} }
...@@ -493,15 +503,15 @@ func NewΔPPTreeSubSet() *ΔPPTreeSubSet { ...@@ -493,15 +503,15 @@ func NewΔPPTreeSubSet() *ΔPPTreeSubSet {
func (δ *ΔPPTreeSubSet) Update(δ2 *ΔPPTreeSubSet) { func (δ *ΔPPTreeSubSet) Update(δ2 *ΔPPTreeSubSet) {
δ.Del.UnionInplace(δ2.Del) δ.Del.UnionInplace(δ2.Del)
δ.Add.UnionInplace(δ2.Add) δ.Add.UnionInplace(δ2.Add)
for oid, δnc := range δ2.δnchildNonLeafs { for oid, δnc := range δ2.ΔnchildNonLeafs {
δ.δnchildNonLeafs[oid] += δnc δ.ΔnchildNonLeafs[oid] += δnc
} }
} }
// Reverse changes δ=diff(A->B) to δ'=diff(A<-B). // Reverse changes δ=diff(A->B) to δ'=diff(A<-B).
func (δ *ΔPPTreeSubSet) Reverse() { func (δ *ΔPPTreeSubSet) Reverse() {
δ.Del, δ.Add = δ.Add, δ.Del δ.Del, δ.Add = δ.Add, δ.Del
// δnchildNonLeafs stays the same // ΔnchildNonLeafs stays the same
} }
...@@ -514,7 +524,7 @@ func (S PPTreeSubSet) ApplyΔ(δ *ΔPPTreeSubSet) { ...@@ -514,7 +524,7 @@ func (S PPTreeSubSet) ApplyΔ(δ *ΔPPTreeSubSet) {
fmt.Printf(" A: %s\n", S) fmt.Printf(" A: %s\n", S)
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) fmt.Printf(" x: %v\n", δ.ΔnchildNonLeafs)
defer fmt.Printf("\n->B: %s\n", S) defer fmt.Printf("\n->B: %s\n", S)
} }
...@@ -523,8 +533,8 @@ func (S PPTreeSubSet) ApplyΔ(δ *ΔPPTreeSubSet) { ...@@ -523,8 +533,8 @@ func (S PPTreeSubSet) ApplyΔ(δ *ΔPPTreeSubSet) {
δ.Add.verify() δ.Add.verify()
defer S.verify() defer S.verify()
S.xfixup(-1, δ.δnchildNonLeafs) S.xfixup(-1, δ.ΔnchildNonLeafs)
S.xDifferenceInplace(δ.Del) S.xDifferenceInplace(δ.Del)
S.xUnionInplace(δ.Add) S.xUnionInplace(δ.Add)
S.xfixup(+1, δ.δnchildNonLeafs) S.xfixup(+1, δ.ΔnchildNonLeafs)
} }
...@@ -132,7 +132,7 @@ func δZConnectTracked(δZv []zodb.Oid, T blib.PPTreeSubSet) (δZTC setOid, δto ...@@ -132,7 +132,7 @@ func δZConnectTracked(δZv []zodb.Oid, T blib.PPTreeSubSet) (δZTC setOid, δto
// if !root -> δZTC += path through which we reached another node (forming connection) // if !root -> δZTC += path through which we reached another node (forming connection)
path := []zodb.Oid{} path := []zodb.Oid{}
node := δ node := δ
parent := track.parent parent := track.Parent()
for { for {
// reached root // reached root
if parent == zodb.InvalidOid { if parent == zodb.InvalidOid {
...@@ -160,7 +160,7 @@ func δZConnectTracked(δZv []zodb.Oid, T blib.PPTreeSubSet) (δZTC setOid, δto ...@@ -160,7 +160,7 @@ func δZConnectTracked(δZv []zodb.Oid, T blib.PPTreeSubSet) (δZTC setOid, δto
panicf("BUG: .p%s -> %s, but %s is not tracked", node, parent, parent) panicf("BUG: .p%s -> %s, but %s is not tracked", node, parent, parent)
} }
node = parent node = parent
parent = trackUp.parent parent = trackUp.Parent()
} }
} }
...@@ -701,8 +701,8 @@ ABcov: ...@@ -701,8 +701,8 @@ ABcov:
if !pathEqual(apath, bpath) { if !pathEqual(apath, bpath) {
δtrack.Del.AddPath(apath) δtrack.Del.AddPath(apath)
δtrack.Add.AddPath(bpath) δtrack.Add.AddPath(bpath)
if nc := at.nchild; nc != 0 { if nc := at.NChild(); nc != 0 {
δtrack.δnchildNonLeafs[acOid] = nc δtrack.ΔnchildNonLeafs[acOid] = nc
} }
} }
......
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