mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-23 17:51:39 +00:00
Nil keys are OK, deprecate BeginningKey/EndingKey (#101)
* Nil keys are OK, deprecate BeginningKey/EndingKey
This commit is contained in:
29
db/util.go
29
db/util.go
@ -7,8 +7,8 @@ import (
|
||||
func IteratePrefix(db DB, prefix []byte) Iterator {
|
||||
var start, end []byte
|
||||
if len(prefix) == 0 {
|
||||
start = BeginningKey()
|
||||
end = EndingKey()
|
||||
start = nil
|
||||
end = nil
|
||||
} else {
|
||||
start = cp(prefix)
|
||||
end = cpIncr(prefix)
|
||||
@ -35,11 +35,26 @@ func cpIncr(bz []byte) (ret []byte) {
|
||||
ret[i] = byte(0x00)
|
||||
}
|
||||
}
|
||||
return EndingKey()
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsKeyInDomain(key, start, end []byte) bool {
|
||||
leftCondition := bytes.Equal(start, BeginningKey()) || bytes.Compare(key, start) >= 0
|
||||
rightCondition := bytes.Equal(end, EndingKey()) || bytes.Compare(key, end) < 0
|
||||
return leftCondition && rightCondition
|
||||
// See DB interface documentation for more information.
|
||||
func IsKeyInDomain(key, start, end []byte, isReverse bool) bool {
|
||||
if !isReverse {
|
||||
if bytes.Compare(key, start) < 0 {
|
||||
return false
|
||||
}
|
||||
if end != nil && bytes.Compare(end, key) <= 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
if start != nil && bytes.Compare(start, key) < 0 {
|
||||
return false
|
||||
}
|
||||
if end != nil && bytes.Compare(key, end) <= 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user