mirror of
https://github.com/tendermint/tendermint.git
synced 2026-10-01 12:15:45 +00:00
First iteration of the immutable AVL tree
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user