Commit e2614eb3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 231a8e52
......@@ -210,6 +210,29 @@ type δtrackIndex struct {
Add trackIndex
}
// gc1 garbage-collects oid and cleans up its parent down-up.
func (tidx trackIndex) gc1(oid zodb.Oid) {
t, present := tidx[oid]
if !present {
return // already not there
}
if t.nchild != 0 {
panicf("gc %v (nchild != 0)", t)
}
delete(tidx, oid)
parent := t.parent
for parent != zodb.InvalidOid {
t := tidx[parent]
t.nchild--
if t.nchild > 0 {
break
}
delete(tidx, parent)
parent = t.parent
}
}
// ApplyΔ applies δ to trackIdx. XXX
func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
fmt.Printf("\n\nApplyΔ\n")
......@@ -218,22 +241,7 @@ func (tidx trackIndex) ApplyΔ(δ *δtrackIndex) {
// remove leafs and thier parents
for leaf := range δ.DelLeaf {
t, present := tidx[leaf]
if !present {
continue // leaf already not there
}
delete(tidx, leaf)
parent := t.parent
for parent != zodb.InvalidOid {
t := tidx[parent]
t.nchild--
if t.nchild > 0 {
break
}
delete(tidx, parent)
parent = t.parent
}
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