MCPcopy
hub / github.com/google/mangle / GetFacts

Method GetFacts

factstore/factstore.go:571–593  ·  view source on GitHub ↗

GetFacts implementation that looks up facts from an in-memory map.

(a ast.Atom, fn func(ast.Atom) error)

Source from the content-addressed store, hash-verified

569
570// GetFacts implementation that looks up facts from an in-memory map.
571func (s MultiIndexedInMemoryStore) GetFacts(a ast.Atom, fn func(ast.Atom) error) error {
572 if a.Predicate.Arity == 0 {
573 if a, ok := s.constants[a.Predicate]; ok {
574 return fn(a)
575 }
576 return nil
577 }
578 for i := 0; i < a.Predicate.Arity; i++ {
579 // Find a non variable parameter.
580 if _, ok := a.Args[i].(ast.Variable); !ok {
581 h := a.Args[i].Hash()
582 for _, fact := range s.shardsByPredicate[a.Predicate][uint16(i)][h] {
583 if Matches(a.Args, fact.Args) {
584 if err := fn(*fact); err != nil {
585 return err
586 }
587 }
588 }
589 return nil
590 }
591 }
592 return s.getFactsOfFirstVariable(a, fn)
593}
594
595// Add implements the FactStore interface by adding the fact to the backing map.
596func (s MultiIndexedInMemoryStore) Add(a ast.Atom) bool {

Callers

nothing calls this directly

Calls 3

MatchesFunction · 0.85
HashMethod · 0.65

Tested by

no test coverage detected