11package quamina
22
3- // coreMatcher represents an automaton that allows matching sequences of name/value field pairs against
3+ // coreMatcher represents an automaton that allows matching sequences of
4+ // name/value field pairs against
45// patterns, which are combinations of field names and lists of allowed valued field values.
5- // The field names are called "Paths" because they encode, in a jsonpath-ish style, the pathSegments from the
6+ // The field names are called "Paths" because they encode, in a jsonpath-ish
7+ // style, the pathSegments from the
68// root of an incoming object to the leaf field.
7- // Since the order of fields is generally not significant in encoded data objects, the fields are sorted
9+ // Since the order of fields is generally not significant in encoded data
10+ // objects, the fields are sorted
811// by name before constructing the automaton, and so are the incoming field lists to be matched, allowing
912// the automaton to work.
1013
@@ -32,9 +35,6 @@ type coreStart struct {
3235 presumedExistFalseMatches * matchSet
3336}
3437
35- // X for anything, should eventually be a generic?
36- type X any
37-
3838func newCoreMatcher () * coreMatcher {
3939 m := coreMatcher {}
4040 m .updateable .Store (& coreStart {
@@ -44,6 +44,7 @@ func newCoreMatcher() *coreMatcher {
4444 })
4545 return & m
4646}
47+
4748func (m * coreMatcher ) start () * coreStart {
4849 return m .updateable .Load ().(* coreStart )
4950}
@@ -146,7 +147,6 @@ type proposedTransition struct {
146147// matchesForSortedFields runs the provided list of name/value pairs against the automaton and returns
147148// a possibly-empty list of the patterns that match
148149func (m * coreMatcher ) matchesForSortedFields (fields []Field ) * matchSet {
149-
150150 failedExistsFalseMatches := newMatchSet ()
151151 matches := newMatchSet ()
152152
@@ -203,14 +203,16 @@ func (m *coreMatcher) matchesForSortedFields(fields []Field) *matchSet {
203203
204204// Arrays are invisible in the automaton. That is to say, if an event has
205205// { "a": [ 1, 2, 3 ] }
206- // Then the fields will be a/1, a/2, and a/3
207- // Same for {"a": [[1, 2], 3]} or any other permutation
208- // So if you have {"a": [ { "b": 1, "c": 2}, {"b": 3, "c": 4}] }
209- // then a pattern like { "a": { "b": 1, "c": 4 } } would match.
210- // To prevent that from happening, each ArrayPos contains two numbers; the first identifies the array in
211- // the event that this name/val occurred in, the second the position in the array. We don't allow
212- // transitioning between field values that occur in different positions in the same array.
213- // See the arrays_test unit test for more examples.
206+ // Then the fields will be a/1, a/2, and a/3 Same for {"a": [[1, 2], 3]} or any
207+ // other permutation So if you have
208+ // {"a": [ { "b": 1, "c": 2}, {"b": 3, "c": 4}] }
209+ // then a pattern like
210+ // { "a": { "b": 1, "c": 4 } }
211+ // would match. To prevent that from happening, each ArrayPos contains two
212+ // numbers; the first identifies the array in
213+ // the event that this name/val occurred in, the second the position in the array. We don't allow
214+ // transitioning between field values that occur in different positions in the same array.
215+ // See the arrays_test unit test for more examples.
214216func noArrayTrailConflict (from []ArrayPos , to []ArrayPos ) bool {
215217 for _ , fromAPos := range from {
216218 for _ , toAPos := range to {
0 commit comments