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

Method GetFacts

factstore/factstore.go:760–784  ·  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

758
759// GetFacts implementation that looks up facts from an in-memory map.
760func (s *MultiIndexedArrayInMemoryStore) GetFacts(a ast.Atom, fn func(ast.Atom) error) error {
761 if a.Predicate.Arity == 0 {
762 if a, ok := s.constants[a.Predicate]; ok {
763 return fn(a)
764 }
765 return nil
766 }
767 for i := 0; i < a.Predicate.Arity; i++ {
768 // Find a non variable parameter.
769 if _, ok := a.Args[i].(ast.Variable); !ok {
770 h := a.Args[i].Hash()
771 for _, facts := range s.shardsByPredicate[a.Predicate][uint16(i)][h] {
772 for _, fact := range facts {
773 if Matches(a.Args, fact.Args) {
774 if err := fn(*fact); err != nil {
775 return err
776 }
777 }
778 }
779 }
780 return nil
781 }
782 }
783 return s.getFactsOfFirstVariable(a, fn)
784}
785
786// Add implements the FactStore interface by adding the fact to the backing map.
787func (s *MultiIndexedArrayInMemoryStore) Add(a ast.Atom) bool {

Callers

nothing calls this directly

Calls 3

MatchesFunction · 0.85
HashMethod · 0.65

Tested by

no test coverage detected