Commit 1a0cfd54 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3604f4a5
...@@ -57,54 +57,6 @@ type nodeInTree struct { ...@@ -57,54 +57,6 @@ type nodeInTree struct {
} }
// verify checks internal consistency of S.
func (S PPTreeSubSet) verify() {
// XXX !debug -> return
var badv []string
badf := func(format string, argv ...interface{}) {
badv = append(badv, fmt.Sprintf(format, argv...))
}
defer func() {
if badv != nil {
emsg := fmt.Sprintf("S.verify: fail:\n\n")
for _, bad := range badv {
emsg += fmt.Sprintf("- %s\n", bad)
}
emsg += fmt.Sprintf("\nS: %s\n", S)
panic(emsg)
}
}()
// recompute {} oid -> children and verify .nchild against it
children := map[zodb.Oid]SetOid{}
for oid, t := range S {
if t.parent != zodb.InvalidOid {
cc, ok := children[t.parent]
if !ok {
cc = SetOid{}
children[t.parent] = cc
}
cc.Add(oid)
}
}
for oid, t := range S {
cc := children[oid]
if t.nchild != len(cc) {
badf("[%s].nchild=%d children: %s", oid, t.nchild, cc)
}
}
// verify that all pointed-to parents are present in the set (= PP-connected)
for oid := range children {
_, ok := S[oid]
if !ok {
badf("oid %s is pointed to via some .parent, but is not present in the set", oid)
}
}
}
// 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.
...@@ -348,8 +300,60 @@ func (S PPTreeSubSet) gc1(oid zodb.Oid) { ...@@ -348,8 +300,60 @@ func (S PPTreeSubSet) gc1(oid zodb.Oid) {
} }
// ---- verify ----
// verify checks internal consistency of S.
func (S PPTreeSubSet) verify() {
// XXX !debug -> return
var badv []string
badf := func(format string, argv ...interface{}) {
badv = append(badv, fmt.Sprintf(format, argv...))
}
defer func() {
if badv != nil {
emsg := fmt.Sprintf("S.verify: fail:\n\n")
for _, bad := range badv {
emsg += fmt.Sprintf("- %s\n", bad)
}
emsg += fmt.Sprintf("\nS: %s\n", S)
panic(emsg)
}
}()
// recompute {} oid -> children and verify .nchild against it
children := map[zodb.Oid]SetOid{}
for oid, t := range S {
if t.parent != zodb.InvalidOid {
cc, ok := children[t.parent]
if !ok {
cc = SetOid{}
children[t.parent] = cc
}
cc.Add(oid)
}
}
for oid, t := range S {
cc := children[oid]
if t.nchild != len(cc) {
badf("[%s].nchild=%d children: %s", oid, t.nchild, cc)
}
}
// verify that all pointed-to parents are present in the set (= PP-connected)
for oid := range children {
_, ok := S[oid]
if !ok {
badf("oid %s is pointed to via some .parent, but is not present in the set", oid)
}
}
}
// ---- misc ----
// Clone returns copy of the set. // Clone returns copy of the set.
// XXX place
func (orig PPTreeSubSet) Clone() PPTreeSubSet { func (orig PPTreeSubSet) Clone() PPTreeSubSet {
klon := make(PPTreeSubSet, len(orig)) klon := make(PPTreeSubSet, len(orig))
for oid, t := range orig { for oid, t := range orig {
...@@ -359,7 +363,6 @@ func (orig PPTreeSubSet) Clone() PPTreeSubSet { ...@@ -359,7 +363,6 @@ func (orig PPTreeSubSet) Clone() PPTreeSubSet {
} }
// equal returns whether a == b. // equal returns whether a == b.
// 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
...@@ -384,7 +387,6 @@ func (t nodeInTree) String() string { ...@@ -384,7 +387,6 @@ func (t nodeInTree) String() string {
} }
// ---- diff/patch ---- // ---- diff/patch ----
// ΔPPTreeSubSet represents a change to PPTreeSubSet. // ΔPPTreeSubSet represents a change to PPTreeSubSet.
......
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