Nil keys are OK, deprecate BeginningKey/EndingKey (#101)

* Nil keys are OK, deprecate BeginningKey/EndingKey
This commit is contained in:
Jae Kwon
2017-12-17 13:11:28 -08:00
committed by GitHub
parent aab2d70dd3
commit 4ce8448d7f
10 changed files with 421 additions and 353 deletions

View File

@ -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
}
}