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

Method GetFacts

factstore/factstore.go:414–433  ·  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

412
413// GetFacts implementation that looks up facts from an in-memory map.
414func (s IndexedInMemoryStore) GetFacts(a ast.Atom, fn func(ast.Atom) error) error {
415 if a.Predicate.Arity == 0 {
416 if a, ok := s.constants[a.Predicate]; ok {
417 return fn(a)
418 }
419 return nil
420 }
421 if _, ok := a.Args[0].(ast.Variable); ok {
422 return s.getFactsOfFirstVariable(a, fn)
423 }
424 h := a.Args[0].Hash()
425 for _, fact := range s.shardsByPredicate[a.Predicate][h] {
426 if Matches(a.Args, fact.Args) {
427 if err := fn(fact); err != nil {
428 return err
429 }
430 }
431 }
432 return nil
433}
434
435// Add implements the FactStore interface by adding the fact to the backing map.
436func (s IndexedInMemoryStore) Add(a ast.Atom) bool {

Callers

nothing calls this directly

Calls 3

MatchesFunction · 0.85
HashMethod · 0.65

Tested by

no test coverage detected