Example #1
0
func NewBroker() *Broker {
	minFill := MaxRTreeNodes * MinFillRatio
	return &Broker{
		ConsumerTree: rtree.New(MaxRTreeNodes, int(minFill)),
		ConsumerMap:  make(map[string]*Consumer, DefaultMapSize),
	}
}
Example #2
0
func NewBroker() *Broker {
	broker := new(Broker)
	broker.URL = ""
	minFill := MaxRTreeNodes * MinFillRatio
	broker.ConsumerTree = rtree.New(MaxRTreeNodes, int(minFill))
	return broker
}
Example #3
0
func TestRTree(t *testing.T) {
	tree := rtree.New(10, 4)

	nodes := make([]*rtree.RTreeNode, 0, testCount)
	for n := 0; n < testCount; n++ {
		bounds := randomRect()
		fmt.Println(bounds)
		dummy := &Dummy{A: 1}
		node := tree.Insert(dummy, bounds)
		nodes = append(nodes, node)
	}

	count := 0
	tree.VisitAll(func(value interface{}, bounds rtree.Rect) {
		count++
		//fmt.Println(value.(*Dummy).A)
	})

	if count != testCount {
		t.Error("Failed to visit all nodes")
	}

	for _, n := range nodes {
		n.Remove()
	}

	count = 0
	tree.VisitAll(func(value interface{}, bounds rtree.Rect) {
		count++
	})

	if count != 0 {
		t.Error("Failed to remove all nodes")
	}

	for n := 0; n < testCount; n++ {
		bounds := randomRect()
		fmt.Println(bounds)
		dummy := &Dummy{A: 1}
		nodes[n] = tree.Insert(dummy, bounds)
	}

	count = 0
	tree.VisitAll(func(value interface{}, bounds rtree.Rect) {
		count++
		//fmt.Println(value.(*Dummy).A)
	})

	if count != testCount {
		t.Error("Failed to visit all nodes")
	}

}