mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 23:02:16 +00:00
58 lines
1.0 KiB
Go
58 lines
1.0 KiB
Go
|
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
|
||
|
}
|
||
|
|
||
|
|