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