added comments and got rid of fixed variable

This commit is contained in:
Sunny Aggarwal 2018-04-06 11:29:25 +02:00
parent 348e28a4b5
commit 4bcfcd5cc8
2 changed files with 7 additions and 6 deletions

2
Gopkg.lock generated
View File

@ -458,6 +458,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "ed1f3f7f1728cd02945f90ca780e9bdc982573a36a5cc8d7e9f19fb40ba2ca19"
inputs-digest = "67298e1f8058b85f082dbd32123f2779b11bda282616e595141dba41a8675c39"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -231,7 +231,9 @@ func (key *KVStoreKey) String() string {
return fmt.Sprintf("KVStoreKey{%p, %s}", key, key.name)
}
// TODO: Move to TmLibs
// PrefixEndBytes returns the []byte that would end a
// range query for all []byte with a certain prefix
// Deals with last byte of prefix being FF without overflowing
func PrefixEndBytes(prefix []byte) []byte {
if prefix == nil {
return nil
@ -239,17 +241,16 @@ func PrefixEndBytes(prefix []byte) []byte {
end := make([]byte, len(prefix))
copy(end, prefix)
finished := false
for !finished {
for {
if end[len(end)-1] != byte(255) {
end[len(end)-1]++
finished = true
break
} else {
end = end[:len(end)-1]
if len(end) == 0 {
end = nil
finished = true
break
}
}
}