Simplified code of non interleaved spatial query in LevelDB backend.

This commit is contained in:
Sascha L. Teichmann 2014-09-01 18:39:42 +02:00
parent 77a35e7096
commit c096b8bbf1
2 changed files with 13 additions and 13 deletions

View File

@ -80,9 +80,13 @@ func DecodeStringFromBytes(key []byte) (pos int64, err error) {
return strconv.ParseInt(string(key), 10, 64) return strconv.ParseInt(string(key), 10, 64)
} }
func StringToBytes(key int64) []byte {
return []byte(strconv.FormatInt(key, 10))
}
// Encode a block pos to byte slice. // Encode a block pos to byte slice.
func EncodeStringToBytes(key int64) ([]byte, error) { func EncodeStringToBytes(key int64) ([]byte, error) {
return []byte(strconv.FormatInt(key, 10)), nil return StringToBytes(key), nil
} }
func ToBigEndian(key int64) []byte { func ToBigEndian(key int64) []byte {

View File

@ -269,20 +269,17 @@ func (ldbs *LevelDBSession) plainSpatialQuery(first, second []byte, done chan st
for a.Y = c1.Y; a.Y <= c2.Y; a.Y++ { for a.Y = c1.Y; a.Y <= c2.Y; a.Y++ {
b.Y = a.Y b.Y = a.Y
from, to := order(common.CoordToPlain(a), common.CoordToPlain(b)) from, to := order(common.CoordToPlain(a), common.CoordToPlain(b))
var encodedFrom []byte it.Seek(common.StringToBytes(from))
if encodedFrom, err = common.EncodeStringToBytes(from); err != nil { for ; it.Valid(); it.Next() {
log.Printf("encoding key failed: %s", err) var (
return key = it.Key()
} pos int64
it.Seek(encodedFrom) )
for it.Valid() { if pos, err = common.DecodeStringFromBytes(key); err != nil {
key := it.Key()
var decodedKey int64
if decodedKey, err = common.DecodeStringFromBytes(key); err != nil {
log.Printf("decoding key failed: %s", err) log.Printf("decoding key failed: %s", err)
return return
} }
if decodedKey > to { if pos > to {
break break
} }
select { select {
@ -290,7 +287,6 @@ func (ldbs *LevelDBSession) plainSpatialQuery(first, second []byte, done chan st
case <-done: case <-done:
return return
} }
it.Next()
} }
if err = it.GetError(); err != nil { if err = it.GetError(); err != nil {
log.Printf("iterating failed: %s", err) log.Printf("iterating failed: %s", err)