tendermint/merkle/string.go

58 lines
1.0 KiB
Go
Raw Normal View History

package merkle
import "bytes"
type String string
type ByteSlice []byte
func (self String) Equals(other Sortable) bool {
if o, ok := other.(String); ok {
return self == o
} else {
return false
}
}
func (self String) Less(other Sortable) bool {
if o, ok := other.(String); ok {
return self < o
} else {
return false
}
}
func (self String) Hash() int {
bytes := []byte(self)
hash := 0
for i, c := range bytes {
hash += (i+1)*int(c)
}
return hash
}
func (self ByteSlice) Equals(other Sortable) bool {
if o, ok := other.(ByteSlice); ok {
return bytes.Equal(self, o)
} else {
return false
}
}
func (self ByteSlice) Less(other Sortable) bool {
if o, ok := other.(ByteSlice); ok {
return bytes.Compare(self, o) < 0 // -1 if a < b
} else {
return false
}
}
func (self ByteSlice) Hash() int {
hash := 0
for i, c := range self {
hash += (i+1)*int(c)
}
return hash
}