Skip to content

Commit

Permalink
added comments and got rid of fixed variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnya97 committed Apr 6, 2018
1 parent 348e28a commit 4bcfcd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,26 @@ 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
}

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
}
}
}
Expand Down

0 comments on commit 4bcfcd5

Please sign in to comment.