Commit e2614eb3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 231a8e52
......@@ -210,20 +210,17 @@ type δtrackIndex struct {
Add trackIndex
}
// ApplyΔ applies δ to trackIdx. XXX
func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
fmt.Printf("\n\nApplyΔ\n")
fmt.Printf("\tDelLeaf: %v\n", δ.DelLeaf)
fmt.Printf("\tAdd: %v\n", δ.Add)
// remove leafs and thier parents
for leaf := range δ.DelLeaf {
t, present := tidx[leaf]
// gc1 garbage-collects oid and cleans up its parent down-up.
func (tidx trackIndex) gc1(oid zodb.Oid) {
t, present := tidx[oid]
if !present {
continue // leaf already not there
return // already not there
}
if t.nchild != 0 {
panicf("gc %v (nchild != 0)", t)
}
delete(tidx, leaf)
delete(tidx, oid)
parent := t.parent
for parent != zodb.InvalidOid {
t := tidx[parent]
......@@ -234,6 +231,17 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
delete(tidx, parent)
parent = t.parent
}
}
// ApplyΔ applies δ to trackIdx. XXX
func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
fmt.Printf("\n\nApplyΔ\n")
fmt.Printf("\tDelLeaf: %v\n", δ.DelLeaf)
fmt.Printf("\tAdd: %v\n", δ.Add)
// remove leafs and thier parents
for leaf := range δ.DelLeaf {
tidx.gc1(leaf)
}
// process adds
......@@ -254,9 +262,16 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
δnchild[t.parent] += 1 // remeber to nchild++ in parent
}
}
gcq := []zodb.Oid{}
for parent, δnc := range δnchild {
tidx[parent].nchild += δnc
// XXX .nchild == 0 - remove ?
t := tidx[parent]
t.nchild += δnc
if t.nchild == 0 {
gcq = append(gcq, t.parent)
}
}
for _, oid := range gcq {
tidx.gc1(oid)
}
}
......
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