GetFacts implementation that looks up facts from an in-memory map.
(a ast.Atom, fn func(ast.Atom) error)
| 758 | |
| 759 | // GetFacts implementation that looks up facts from an in-memory map. |
| 760 | func (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. |
| 787 | func (s *MultiIndexedArrayInMemoryStore) Add(a ast.Atom) bool { |
nothing calls this directly
no test coverage detected