Commit bb76489c authored by Kirill Smelkov's avatar Kirill Smelkov

.

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