Array of values instead of map for whereins.

This commit is contained in:
Alex Roitman 2020-03-24 22:08:55 -07:00
parent 27c6980f82
commit 9e7766b346
2 changed files with 12 additions and 9 deletions

View File

@ -35,8 +35,8 @@ func BenchmarkFieldMatch(t *testing.B) {
{"bar", false, 10, false, 30},
},
whereins: []whereinT{
{"foo", map[float64]struct{}{1: {}, 2: {}}},
{"bar", map[float64]struct{}{11: {}, 25: {}}},
{"foo", []float64{1, 2}},
{"bar", []float64{11, 25}},
},
fmap: map[string]int{"foo": 0, "bar": 1},
farr: []string{"bar", "foo"},

View File

@ -159,12 +159,16 @@ func zMinMaxFromWheres(wheres []whereT) (minZ, maxZ float64) {
type whereinT struct {
field string
valMap map[float64]struct{}
valArr []float64
}
func (wherein whereinT) match(value float64) bool {
_, ok := wherein.valMap[value]
return ok
for _, val := range wherein.valArr {
if val == value {
return true
}
}
return false
}
type whereevalT struct {
@ -342,9 +346,8 @@ func (s *Server) parseSearchScanBaseTokens(
err = errInvalidArgument(nvalsStr)
return
}
valMap := make(map[float64]struct{})
valArr := make([]float64, nvals)
var val float64
var empty struct{}
for i = 0; i < nvals; i++ {
if vs, valStr, ok = tokenval(vs); !ok || valStr == "" {
err = errInvalidNumberOfArguments
@ -354,9 +357,9 @@ func (s *Server) parseSearchScanBaseTokens(
err = errInvalidArgument(valStr)
return
}
valMap[val] = empty
valArr = append(valArr, val)
}
t.whereins = append(t.whereins, whereinT{field, valMap})
t.whereins = append(t.whereins, whereinT{field, valArr})
continue
case "whereevalsha":
fallthrough