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

Method GetFactsAt

factstore/temporal.go:172–194  ·  view source on GitHub ↗

GetFactsAt returns facts valid at a specific point in time. Uses interval tree for O(log n + k) query performance.

(query ast.Atom, t time.Time, fn func(TemporalFact) error)

Source from the content-addressed store, hash-verified

170// GetFactsAt returns facts valid at a specific point in time.
171// Uses interval tree for O(log n + k) query performance.
172func (s *TemporalStore) GetFactsAt(query ast.Atom, t time.Time, fn func(TemporalFact) error) error {
173 predMap, ok := s.facts[query.Predicate]
174 if !ok {
175 return nil
176 }
177
178 timestamp := t.UnixNano()
179
180 for hash, tree := range predMap {
181 atom := s.atoms[hash]
182 if !Matches(query.Args, atom.Args) {
183 continue
184 }
185
186 err := tree.QueryPoint(timestamp, func(interval ast.Interval) error {
187 return fn(TemporalFact{Atom: atom, Interval: interval})
188 })
189 if err != nil {
190 return err
191 }
192 }
193 return nil
194}
195
196// GetFactsDuring returns facts that overlap with the given interval.
197// Uses interval tree for O(log n + k) query performance.

Calls 2

MatchesFunction · 0.85
QueryPointMethod · 0.80

Tested by 2