OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package datastore | 5 package datastore |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "sort" | 10 "sort" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 if q.eqFilts == nil { | 263 if q.eqFilts == nil { |
264 q.eqFilts = make(map[string]PropertySlice, 1) | 264 q.eqFilts = make(map[string]PropertySlice, 1) |
265 } | 265 } |
266 s := q.eqFilts[field] | 266 s := q.eqFilts[field] |
267 for _, value := range values { | 267 for _, value := range values { |
268 p := Property{} | 268 p := Property{} |
269 if q.err = p.SetValue(value, ShouldIndex); q.err != nil { | 269 if q.err = p.SetValue(value, ShouldIndex); q.err != nil { |
270 return | 270 return |
271 } | 271 } |
272 idx := sort.Search(len(s), func(i int) bool { | 272 idx := sort.Search(len(s), func(i int) bool { |
273 » » » » » return s[i].Equal(&p) | 273 » » » » » // s[i] >= p is the same as: |
274 » » » » » return s[i].Equal(&p) || p.Less(&s[i]) | |
274 }) | 275 }) |
275 » » » » if idx == len(s) { | 276 » » » » if idx == len(s) || !s[idx].Equal(&p) { |
276 » » » » » s = append(s, p) | 277 » » » » » s = append(s, Property{}) |
277 » » » » » sort.Sort(s) | 278 » » » » » copy(s[idx+1:], s[idx:]) |
dnj
2015/10/15 02:23:46
nit: WDYT about making eqfilts a binheap?
| |
279 » » » » » s[idx] = p | |
278 } | 280 } |
279 } | 281 } |
280 q.eqFilts[field] = s | 282 q.eqFilts[field] = s |
281 } | 283 } |
282 }) | 284 }) |
283 } | 285 } |
284 | 286 |
285 func (q *Query) reserved(field string) bool { | 287 func (q *Query) reserved(field string) bool { |
286 if field == "__key__" { | 288 if field == "__key__" { |
287 return false | 289 return false |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 if q.keysOnly { | 727 if q.keysOnly { |
726 p("KeysOnly") | 728 p("KeysOnly") |
727 } | 729 } |
728 | 730 |
729 if _, err := ret.WriteRune(')'); err != nil { | 731 if _, err := ret.WriteRune(')'); err != nil { |
730 panic(err) | 732 panic(err) |
731 } | 733 } |
732 | 734 |
733 return ret.String() | 735 return ret.String() |
734 } | 736 } |
OLD | NEW |