mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Fixed endless loop bug in LevelDB interleaved spatial query. Simplified code.
This commit is contained in:
parent
f4baf63247
commit
77a35e7096
@ -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) {
|
||||
|
22
leveldb.go
22
leveldb.go
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user