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