GetFacts implementation that looks up facts from an in-memory map.
(a ast.Atom, fn func(ast.Atom) error)
| 412 | |
| 413 | // GetFacts implementation that looks up facts from an in-memory map. |
| 414 | func (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. |
| 436 | func (s IndexedInMemoryStore) Add(a ast.Atom) bool { |
nothing calls this directly
no test coverage detected