Skip to content

Commit

Permalink
trie: refactor StackTrie.getDiffIndex()
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 26, 2021
1 parent 50c1df8 commit 26f8056
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions trie/stacktrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ func (st *StackTrie) Reset() {
// at which the chunk pointed by st.keyOffset is different from
// the same chunk in the full key.
func (st *StackTrie) getDiffIndex(key []byte) int {
diffindex := 0
for ; diffindex < len(st.key) && st.key[diffindex] == key[diffindex]; diffindex++ {
for idx, nibble := range st.key {
if nibble != key[idx] {
return idx
}
}
return diffindex
return len(st.key)
}

// Helper function to that inserts a (key, value) pair into
Expand Down

0 comments on commit 26f8056

Please sign in to comment.