예제 #1
0
func NewBroker() *Broker {
	minFill := MaxRTreeNodes * MinFillRatio
	return &Broker{
		ConsumerTree: rtree.New(MaxRTreeNodes, int(minFill)),
		ConsumerMap:  make(map[string]*Consumer, DefaultMapSize),
	}
}
예제 #2
0
func NewBroker() *Broker {
	broker := new(Broker)
	broker.URL = ""
	minFill := MaxRTreeNodes * MinFillRatio
	broker.ConsumerTree = rtree.New(MaxRTreeNodes, int(minFill))
	return broker
}
예제 #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")
	}

}