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