Ejemplo n.º 1
0
func (ind *indices) getNode(ref ast.Ref) *indicesNode {
	hashCode := ref.Hash()
	for entry := ind.table[hashCode]; entry != nil; entry = entry.next {
		if entry.key.Equal(ref) {
			return entry
		}
	}
	return nil
}
Ejemplo n.º 2
0
// Drop removes the index for the reference.
func (ind *indices) Drop(ref ast.Ref) {
	hashCode := ref.Hash()
	var prev *indicesNode
	for entry := ind.table[hashCode]; entry != nil; entry = entry.next {
		if entry.key.Equal(ref) {
			if prev == nil {
				ind.table[hashCode] = entry.next
			} else {
				prev.next = entry.next
			}
			return
		}
	}
}
Ejemplo n.º 3
0
// Build initializes the references' index by walking the store for the reference and
// creating the index that maps values to bindings.
func (ind *indices) Build(ctx context.Context, store Store, txn Transaction, ref ast.Ref) error {
	index := newBindingIndex()
	ind.registerTriggers(store)
	err := iterStorage(ctx, store, txn, ref, ast.EmptyRef(), ast.NewValueMap(), func(bindings *ast.ValueMap, val interface{}) {
		index.Add(val, bindings)
	})
	if err != nil {
		return err
	}
	hashCode := ref.Hash()
	head := ind.table[hashCode]
	entry := &indicesNode{
		key:  ref,
		val:  index,
		next: head,
	}
	ind.table[hashCode] = entry
	return nil
}