Commit bb76489c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7ffbe6ae
......@@ -256,14 +256,13 @@ func (A PPTreeSubSet) xUnionInplace(B PPTreeSubSet) {
}
// fixup performs scheduled δnchild adjustment.
// XXX place
func (A PPTreeSubSet) fixup(δnchild map[zodb.Oid]int) {
A.xfixup(+1, δnchild)
}
func (A PPTreeSubSet) 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 := A[oid] // t != nil as A is PP-connected
t.nchild += sign*δnc
if t.nchild == 0 && /* not root node */t.parent != zodb.InvalidOid {
gcq = append(gcq, oid)
......@@ -277,8 +276,8 @@ func (A PPTreeSubSet) xfixup(sign int, δnchild map[zodb.Oid]int) {
}
// gc1 garbage-collects oid and cleans up its parent down-up.
func (tidx PPTreeSubSet) gc1(oid zodb.Oid) {
t, present := tidx[oid]
func (S PPTreeSubSet) gc1(oid zodb.Oid) {
t, present := S[oid]
if !present {
return // already not there
}
......@@ -286,15 +285,15 @@ func (tidx PPTreeSubSet) gc1(oid zodb.Oid) {
panicf("gc %s %v (nchild != 0)", oid, t)
}
delete(tidx, oid)
delete(S, oid)
oid = t.parent
for oid != zodb.InvalidOid {
t := tidx[oid]
t := S[oid]
t.nchild--
if t.nchild > 0 || /* root node */t.parent == zodb.InvalidOid {
break
}
delete(tidx, oid)
delete(S, oid)
oid = t.parent
}
}
......@@ -317,35 +316,36 @@ func (A PPTreeSubSet) UnionInplace(B PPTreeSubSet) {
A.xUnionInplace(B)
}
// ApplyΔ applies δ to trackIdx. XXX
func (tidx PPTreeSubSet) ApplyΔ(δ *ΔPPTreeSubSet) {
// ApplyΔ applies δ to S.
//
// See ΔPPTreeSubSet documentation for details.
func (S PPTreeSubSet) ApplyΔ(δ *ΔPPTreeSubSet) {
if debugPPSet {
fmt.Printf("\n\nApplyΔ\n")
fmt.Printf(" A: %s\n", tidx)
fmt.Printf(" A: %s\n", S)
fmt.Printf(" -: %s\n", δ.Del)
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", S)
}
tidx.verify()
S.verify()
δ.Del.verify()
δ.Add.verify()
defer tidx.verify()
defer S.verify()
tidx.xfixup(-1, δ.δnchildNonLeafs)
tidx.xDifferenceInplace(δ.Del)
tidx.xUnionInplace(δ.Add)
tidx.xfixup(+1, δ.δnchildNonLeafs)
S.xfixup(-1, δ.δnchildNonLeafs)
S.xDifferenceInplace(δ.Del)
S.xUnionInplace(δ.Add)
S.xfixup(+1, δ.δnchildNonLeafs)
}
// Path returns path leading to node specified by oid.
//
// The node must be in the set.
// XXX place
func (tidx PPTreeSubSet) Path(oid zodb.Oid) (path []zodb.Oid) {
func (S PPTreeSubSet) Path(oid zodb.Oid) (path []zodb.Oid) {
for {
t, ok := tidx[oid]
t, ok := S[oid]
if !ok {
panicf("node %s is not in the set <- %v", oid, path)
}
......@@ -361,9 +361,8 @@ func (tidx PPTreeSubSet) Path(oid zodb.Oid) (path []zodb.Oid) {
return path
}
// XXX place
// XXX doc
func (tidx PPTreeSubSet) AddNodePath(path []Node) { // XXX Tree|Bucket; path[0] = root
func (S PPTreeSubSet) AddNodePath(path []Node) { // XXX Tree|Bucket; path[0] = root
// XXX assert Tree Tree ... Tree Bucket
// root := path[0].(*Tree).POid()
......@@ -371,12 +370,13 @@ func (tidx PPTreeSubSet) AddNodePath(path []Node) { // XXX Tree|Bucket; path[0]
for _, node := range path {
oidv = append(oidv, node.POid())
}
tidx.AddPath(oidv)
S.AddPath(oidv)
}
func (tidx PPTreeSubSet) AddPath(path []zodb.Oid) {
tidx.verify()
defer tidx.verify()
// XXX doc
func (S PPTreeSubSet) AddPath(path []zodb.Oid) {
S.verify()
defer S.verify()
l := len(path)
if l == 0 {
......@@ -384,7 +384,7 @@ func (tidx PPTreeSubSet) AddPath(path []zodb.Oid) {
}
// don't explicitly keep track of embedded buckets - they all have
// InvalidOid, and thus, if kept in tidx, e.g. T/B1:a and another
// InvalidOid, and thus, if kept in S, e.g. T/B1:a and another
// T/B2:b would lead to InvalidOid having multiple parents.
if l >= 2 && path[l-1] == zodb.InvalidOid {
path = path[:l-1]
......@@ -399,7 +399,7 @@ func (tidx PPTreeSubSet) AddPath(path []zodb.Oid) {
panicf("path has node with invalid oid: %v", path)
}
track, oldTrack = tidx[oid]
track, oldTrack = S[oid]
if !oldTrack {
track = &nodeInTree{parent: parent, nchild: 0} // XXX
/*
......@@ -407,7 +407,7 @@ func (tidx PPTreeSubSet) AddPath(path []zodb.Oid) {
track.holes = SetKey{}
}
*/
tidx[oid] = track
S[oid] = track
// XXX .trackNew += oid
}
if track.parent != parent {
......@@ -438,13 +438,13 @@ func (orig PPTreeSubSet) Clone() PPTreeSubSet {
// equal returns whether a == b.
// XXX place
func (a PPTreeSubSet) equal(b PPTreeSubSet) bool {
if len(a) != len(b) {
func (A PPTreeSubSet) equal(B PPTreeSubSet) bool {
if len(A) != len(B) {
return false
}
for oid, ta := range a {
tb, ok := b[oid]
for oid, ta := range A {
tb, ok := B[oid]
if !ok {
return false
}
......
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