func main() { flag.Parse() if *cpuprofile != "" { f, _ := os.Create(*cpuprofile) pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } start := time.Now() for i := 0; i < iterations; i++ { tree := quadtree.NewQuadTree(0, treeSize, 0, treeSize, elemCount/6) for i := 0; i < elemCount; i++ { x := rand.Float64() * treeSize y := rand.Float64() * treeSize tree.Insert(x, y, i) } vs := []*quadtree.View{tree.View()} col := make([]interface{}, 0, elemCount) fun := func(x, y float64, e interface{}) { col = append(col, e) } tree.Survey(vs, fun) tree.Del(tree.View(), quadtree.SimpleDelete()) println(col) } total := time.Now().Sub(start) println(fstrconv.ItoaComma(elemCount)) println(total.String()) secs := total.Nanoseconds() / (1000 * 1000 * 1000) if secs == 0 { return } println(secs) perSec := elemCount / secs println(fstrconv.ItoaComma(perSec), "elements per second") }
// Starts a goroutine looping listening for messsages on taskChan to process func StartTreeManager(minTreeMax int64, trackMovement bool) { go func() { tree := quadtree.NewQuadTree(maxSouthMetres, maxNorthMetres, maxWestMetres, maxEastMetres, minTreeMax) for { msg := <-taskChan switch msg.op { case msgdef.CInitLocOp: handleInitLoc(msg, tree) case msgdef.CRemoveOp: handleRemove(msg, tree) case msgdef.CMoveOp: handleMove(msg, tree, trackMovement) } } }() }