mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-17 15:48:17 +01:00
Simplified code of non interleaved spatial query in LevelDB backend.
This commit is contained in:
parent
77a35e7096
commit
c096b8bbf1
@ -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 {
|
||||
|
20
leveldb.go
20
leveldb.go
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user