aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/slice.go
blob: 3cedcb18947de0cdfbb4d129df76af63b370f620 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package ethutil

import ()

// Helper function for comparing slices
func CompareIntSlice(a, b []int) bool {
    if len(a) != len(b) {
        return false
    }
    for i, v := range a {
        if v != b[i] {
            return false
        }
    }
    return true
}

// Returns the amount of nibbles that match each other from 0 ...
func MatchingNibbleLength(a, b []int) int {
    i := 0
    for CompareIntSlice(a[:i+1], b[:i+1]) && i < len(b) {
        i += 1
    }

    return i
}