2019-05-27 13:51:49 +00:00
|
|
|
package dbutils
|
|
|
|
|
2021-02-21 18:41:59 +00:00
|
|
|
// NextNibblesSubtree does []byte++. Returns false if overflow.
|
|
|
|
func NextNibblesSubtree(in []byte, out *[]byte) bool {
|
|
|
|
r := (*out)[:len(in)]
|
2020-09-10 12:35:58 +00:00
|
|
|
copy(r, in)
|
|
|
|
for i := len(r) - 1; i >= 0; i-- {
|
2021-02-21 18:41:59 +00:00
|
|
|
if r[i] != 15 { // max value of nibbles
|
2020-09-10 12:35:58 +00:00
|
|
|
r[i]++
|
2021-02-21 18:41:59 +00:00
|
|
|
*out = r
|
|
|
|
return true
|
2020-09-10 12:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r = r[:i] // make it shorter, because in tries after 11ff goes 12, but not 1200
|
|
|
|
}
|
2021-02-21 18:41:59 +00:00
|
|
|
*out = r
|
|
|
|
return false
|
2020-09-10 12:35:58 +00:00
|
|
|
}
|