Beispiel #1
0
func (qdi QuadDirectionIndex) Tree(d quad.Direction, id int64) *b.Tree {
	if d < quad.Subject || d > quad.Label {
		panic("illegal direction")
	}
	tree, ok := qdi.index[d-1][id]
	if !ok {
		tree = b.TreeNew(cmp)
		qdi.index[d-1][id] = tree
	}
	return tree
}
Beispiel #2
0
func (qdi *QuadDirectionIndex) Tree(d quad.Direction, id int64) *Tree {
	if d < quad.Subject || d > quad.Label {
		panic("illegal direction")
	}
	qdi.mu.RLock()
	tree, ok := qdi.index[d-1][id]
	qdi.mu.RUnlock()
	if !ok {
		qdi.mu.Lock()
		tree, ok = qdi.index[d-1][id]
		if !ok {
			tree = &Tree{tree: b.TreeNew(cmp)}
			qdi.index[d-1][id] = tree
		}
		qdi.mu.Unlock()
	}
	return tree
}