mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 09:10:17 +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
|
return []byte(strconv.FormatInt(key, 10)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncodeToBigEndian(key int64) (enc []byte, err error) {
|
func ToBigEndian(key int64) []byte {
|
||||||
enc = make([]byte, 8)
|
enc := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint64(enc, uint64(key))
|
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) {
|
func DecodeFromBigEndian(key []byte) (int64, error) {
|
||||||
return int64(binary.BigEndian.Uint64(key)), nil
|
return FromBigEndian(key), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoordToInterleaved(c Coord) (result int64) {
|
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)
|
zmin, zmax = order(zmin, zmax)
|
||||||
var (
|
var (
|
||||||
cub = common.Cuboid{P1: c1, P2: c2}
|
cub = common.Cuboid{P1: c1, P2: c2}
|
||||||
zcode = zmin
|
|
||||||
err error
|
err error
|
||||||
encodedKey []byte
|
encodedKey []byte
|
||||||
)
|
)
|
||||||
SEEK:
|
|
||||||
if encodedKey, err = common.EncodeToBigEndian(zcode); err != nil {
|
it.Seek(common.ToBigEndian(zmin))
|
||||||
log.Printf("error encoding key: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
it.Seek(encodedKey)
|
|
||||||
for it.Valid() {
|
for it.Valid() {
|
||||||
if zcode, err = common.DecodeFromBigEndian(it.Key()); err != nil {
|
zcode := common.FromBigEndian(it.Key())
|
||||||
log.Printf("error decoding key: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if zcode > zmax {
|
if zcode > zmax {
|
||||||
break
|
break
|
||||||
@ -366,12 +358,10 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
|
|||||||
case <-done:
|
case <-done:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
zmin = common.NaiveBigMin(zmin, zmax, zcode)
|
|
||||||
goto SEEK
|
|
||||||
}
|
|
||||||
|
|
||||||
it.Next()
|
it.Next()
|
||||||
|
} else {
|
||||||
|
it.Seek(common.ToBigEndian(common.NaiveBigMin(zmin, zmax, zcode)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err = it.GetError(); err != nil {
|
if err = it.GetError(); err != nil {
|
||||||
log.Printf("error while iterating: %s", err)
|
log.Printf("error while iterating: %s", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user