forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice.go
53 lines (43 loc) · 758 Bytes
/
slice.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package trie
import (
"bytes"
"math"
)
// 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 []byte) int {
var i, length = 0, int(math.Min(float64(len(a)), float64(len(b))))
for i < length {
if a[i] != b[i] {
break
}
i++
}
return i
}
func HasTerm(s []byte) bool {
return s[len(s)-1] == 16
}
func RemTerm(s []byte) []byte {
if HasTerm(s) {
return s[:len(s)-1]
}
return s
}
func BeginsWith(a, b []byte) bool {
if len(b) > len(a) {
return false
}
return bytes.Equal(a[:len(b)], b)
}