github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/trie/slice.go (about)

     1  package trie
     2  
     3  import (
     4  	"bytes"
     5  	"math"
     6  )
     7  
     8  // Helper function for comparing slices
     9  func CompareIntSlice(a, b []int) bool {
    10  	if len(a) != len(b) {
    11  		return false
    12  	}
    13  	for i, v := range a {
    14  		if v != b[i] {
    15  			return false
    16  		}
    17  	}
    18  	return true
    19  }
    20  
    21  // Returns the amount of nibbles that match each other from 0 ...
    22  func MatchingNibbleLength(a, b []byte) int {
    23  	var i, length = 0, int(math.Min(float64(len(a)), float64(len(b))))
    24  
    25  	for i < length {
    26  		if a[i] != b[i] {
    27  			break
    28  		}
    29  		i++
    30  	}
    31  
    32  	return i
    33  }
    34  
    35  func HasTerm(s []byte) bool {
    36  	return s[len(s)-1] == 16
    37  }
    38  
    39  func RemTerm(s []byte) []byte {
    40  	if HasTerm(s) {
    41  		return s[:len(s)-1]
    42  	}
    43  
    44  	return s
    45  }
    46  
    47  func BeginsWith(a, b []byte) bool {
    48  	if len(b) > len(a) {
    49  		return false
    50  	}
    51  
    52  	return bytes.Equal(a[:len(b)], b)
    53  }