implemented bsp metrics
This commit is contained in:
31
internal/bsp/metrics.go
Normal file
31
internal/bsp/metrics.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package bsp
|
||||
|
||||
type Stats struct {
|
||||
Nodes int
|
||||
Leaves int
|
||||
MaxDepth int
|
||||
TotalSegs int // Summe Segmente in Leaves (nach Splits)
|
||||
}
|
||||
|
||||
func Measure(n *Node) Stats {
|
||||
var st Stats
|
||||
var rec func(*Node, int)
|
||||
rec = func(x *Node, d int) {
|
||||
if x == nil {
|
||||
return
|
||||
}
|
||||
if d > st.MaxDepth {
|
||||
st.MaxDepth = d
|
||||
}
|
||||
if x.Leaf != nil {
|
||||
st.Leaves++
|
||||
st.TotalSegs += len(x.Leaf.Segs)
|
||||
return
|
||||
}
|
||||
st.Nodes++
|
||||
rec(x.Left, d+1)
|
||||
rec(x.Right, d+1)
|
||||
}
|
||||
rec(n, 0)
|
||||
return st
|
||||
}
|
||||
Reference in New Issue
Block a user