Fixed endless loop bug in LevelDB interleaved spatial query. Simplified code.

This commit is contained in:
Sascha L. Teichmann 2014-09-01 18:26:33 +02:00
parent f4baf63247
commit 77a35e7096
2 changed files with 17 additions and 19 deletions

View File

@ -85,14 +85,22 @@ func EncodeStringToBytes(key int64) ([]byte, error) {
return []byte(strconv.FormatInt(key, 10)), nil
}
func EncodeToBigEndian(key int64) (enc []byte, err error) {
enc = make([]byte, 8)
func ToBigEndian(key int64) []byte {
enc := make([]byte, 8)
binary.BigEndian.PutUint64(enc, uint64(key))
return
return enc
}
func EncodeToBigEndian(key int64) ([]byte, error) {
return ToBigEndian(key), nil
}
func FromBigEndian(key []byte) int64 {
return int64(binary.BigEndian.Uint64(key))
}
func DecodeFromBigEndian(key []byte) (int64, error) {
return int64(binary.BigEndian.Uint64(key)), nil
return FromBigEndian(key), nil
}
func CoordToInterleaved(c Coord) (result int64) {

View File

@ -336,21 +336,13 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
zmin, zmax = order(zmin, zmax)
var (
cub = common.Cuboid{P1: c1, P2: c2}
zcode = zmin
err error
encodedKey []byte
)
SEEK:
if encodedKey, err = common.EncodeToBigEndian(zcode); err != nil {
log.Printf("error encoding key: %s", err)
return
}
it.Seek(encodedKey)
it.Seek(common.ToBigEndian(zmin))
for it.Valid() {
if zcode, err = common.DecodeFromBigEndian(it.Key()); err != nil {
log.Printf("error decoding key: %s", err)
return
}
zcode := common.FromBigEndian(it.Key())
if zcode > zmax {
break
@ -366,12 +358,10 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
case <-done:
return
}
} else {
zmin = common.NaiveBigMin(zmin, zmax, zcode)
goto SEEK
}
it.Next()
} else {
it.Seek(common.ToBigEndian(common.NaiveBigMin(zmin, zmax, zcode)))
}
}
if err = it.GetError(); err != nil {
log.Printf("error while iterating: %s", err)