| 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 memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 projectedRaw = make([][]byte, len(decodedProps)) | 66 projectedRaw = make([][]byte, len(decodedProps)) |
| 67 } | 67 } |
| 68 pmap := make(ds.PropertyMap, len(s.project)) | 68 pmap := make(ds.PropertyMap, len(s.project)) |
| 69 for i, p := range s.project { | 69 for i, p := range s.project { |
| 70 if s.distinct != nil { | 70 if s.distinct != nil { |
| 71 projectedRaw[i] = rawData[p.suffixIndex] | 71 projectedRaw[i] = rawData[p.suffixIndex] |
| 72 } | 72 } |
| 73 pmap[p.propertyName] = []ds.Property{decodedProps[p.suffixIndex]
} | 73 pmap[p.propertyName] = []ds.Property{decodedProps[p.suffixIndex]
} |
| 74 } | 74 } |
| 75 if s.distinct != nil { | 75 if s.distinct != nil { |
| 76 » » if !s.distinct.Add(string(bjoin(projectedRaw...))) { | 76 » » if !s.distinct.Add(string(serialize.Join(projectedRaw...))) { |
| 77 return true | 77 return true |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 return s.cb(key, pmap, gc) | 80 return s.cb(key, pmap, gc) |
| 81 } | 81 } |
| 82 | 82 |
| 83 type keysOnlyStrategy struct { | 83 type keysOnlyStrategy struct { |
| 84 cb ds.RawRunCB | 84 cb ds.RawRunCB |
| 85 | 85 |
| 86 dedup stringset.Set | 86 dedup stringset.Set |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 needInvert := suffixFormat[i].Descending | 149 needInvert := suffixFormat[i].Descending |
| 150 | 150 |
| 151 buf.SetInvert(needInvert) | 151 buf.SetInvert(needInvert) |
| 152 decoded[i], err = serialize.ReadProperty(buf, serialize.WithoutC
ontext, globalAppID, ns) | 152 decoded[i], err = serialize.ReadProperty(buf, serialize.WithoutC
ontext, globalAppID, ns) |
| 153 memoryCorruption(err) | 153 memoryCorruption(err) |
| 154 | 154 |
| 155 offset := len(suffix) - buf.Len() | 155 offset := len(suffix) - buf.Len() |
| 156 raw[i] = suffix[:offset] | 156 raw[i] = suffix[:offset] |
| 157 suffix = suffix[offset:] | 157 suffix = suffix[offset:] |
| 158 if needInvert { | 158 if needInvert { |
| 159 » » » raw[i] = invert(raw[i]) | 159 » » » raw[i] = serialize.Invert(raw[i]) |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 return | 163 return |
| 164 } | 164 } |
| 165 | 165 |
| 166 func executeQuery(fq *ds.FinalizedQuery, ns string, isTxn bool, idx, head *memSt
ore, cb ds.RawRunCB) error { | 166 func executeQuery(fq *ds.FinalizedQuery, ns string, isTxn bool, idx, head *memSt
ore, cb ds.RawRunCB) error { |
| 167 rq, err := reduce(fq, ns, isTxn) | 167 rq, err := reduce(fq, ns, isTxn) |
| 168 if err == ds.ErrNullQuery { | 168 if err == ds.ErrNullQuery { |
| 169 return nil | 169 return nil |
| (...skipping 29 matching lines...) Expand all Loading... |
| 199 memoryCorruption(err) | 199 memoryCorruption(err) |
| 200 | 200 |
| 201 for _, col := range rq.suffixFormat { | 201 for _, col := range rq.suffixFormat { |
| 202 err := serialize.WriteIndexColumn(buf, c
ol) | 202 err := serialize.WriteIndexColumn(buf, c
ol) |
| 203 memoryCorruption(err) | 203 memoryCorruption(err) |
| 204 } | 204 } |
| 205 cursorPrefix = buf.Bytes() | 205 cursorPrefix = buf.Bytes() |
| 206 } | 206 } |
| 207 // TODO(riannucci): Do we need to decrement suffix inste
ad of increment | 207 // TODO(riannucci): Do we need to decrement suffix inste
ad of increment |
| 208 // if we're sorting by __key__ DESCENDING? | 208 // if we're sorting by __key__ DESCENDING? |
| 209 » » » return queryCursor(bjoin(cursorPrefix, increment(suffix)
)), nil | 209 » » » return queryCursor(serialize.Join(cursorPrefix, incremen
t(suffix))), nil |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 multiIterate(idxs, func(suffix []byte) bool { | 213 multiIterate(idxs, func(suffix []byte) bool { |
| 214 if offset > 0 { | 214 if offset > 0 { |
| 215 offset-- | 215 offset-- |
| 216 return true | 216 return true |
| 217 } | 217 } |
| 218 if hasLimit { | 218 if hasLimit { |
| 219 if limit <= 0 { | 219 if limit <= 0 { |
| 220 return false | 220 return false |
| 221 } | 221 } |
| 222 limit-- | 222 limit-- |
| 223 } | 223 } |
| 224 | 224 |
| 225 rawData, decodedProps := parseSuffix(ns, rq.suffixFormat, suffix
, -1) | 225 rawData, decodedProps := parseSuffix(ns, rq.suffixFormat, suffix
, -1) |
| 226 | 226 |
| 227 keyProp := decodedProps[len(decodedProps)-1] | 227 keyProp := decodedProps[len(decodedProps)-1] |
| 228 if keyProp.Type() != ds.PTKey { | 228 if keyProp.Type() != ds.PTKey { |
| 229 impossible(fmt.Errorf("decoded index row doesn't end wit
h a Key: %#v", keyProp)) | 229 impossible(fmt.Errorf("decoded index row doesn't end wit
h a Key: %#v", keyProp)) |
| 230 } | 230 } |
| 231 | 231 |
| 232 return strategy.handle( | 232 return strategy.handle( |
| 233 rawData, decodedProps, keyProp.Value().(*ds.Key), | 233 rawData, decodedProps, keyProp.Value().(*ds.Key), |
| 234 getCursorFn(suffix)) | 234 getCursorFn(suffix)) |
| 235 }) | 235 }) |
| 236 | 236 |
| 237 return nil | 237 return nil |
| 238 } | 238 } |
| OLD | NEW |