コード例 #1
0
ファイル: broker.go プロジェクト: hamishm/component-tech
func NewBroker() *Broker {
	minFill := MaxRTreeNodes * MinFillRatio
	return &Broker{
		ConsumerTree: rtree.New(MaxRTreeNodes, int(minFill)),
		ConsumerMap:  make(map[string]*Consumer, DefaultMapSize),
	}
}
コード例 #2
0
ファイル: registry.go プロジェクト: hamishm/component-tech
func NewBroker() *Broker {
	broker := new(Broker)
	broker.URL = ""
	minFill := MaxRTreeNodes * MinFillRatio
	broker.ConsumerTree = rtree.New(MaxRTreeNodes, int(minFill))
	return broker
}
コード例 #3
0
ファイル: rtree_test.go プロジェクト: hamishm/component-tech
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")
	}

}