2014-05-19 20:46:41 -07:00
|
|
|
package merkle
|
|
|
|
|
|
|
|
import (
|
2014-07-01 14:50:24 -07:00
|
|
|
"fmt"
|
|
|
|
. "github.com/tendermint/tendermint/binary"
|
2014-05-19 20:46:41 -07:00
|
|
|
)
|
|
|
|
|
2014-05-21 16:24:50 -07:00
|
|
|
type Value interface {
|
2014-07-01 14:50:24 -07:00
|
|
|
Binary
|
2014-05-21 16:24:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Key interface {
|
2014-07-01 14:50:24 -07:00
|
|
|
Binary
|
|
|
|
Equals(Binary) bool
|
|
|
|
Less(b Binary) bool
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|
|
|
|
|
2014-05-23 17:49:28 -07:00
|
|
|
type Db interface {
|
2014-07-01 14:50:24 -07:00
|
|
|
Get([]byte) []byte
|
2014-07-19 15:19:07 -07:00
|
|
|
Set([]byte, []byte)
|
2014-05-23 17:49:28 -07:00
|
|
|
}
|
|
|
|
|
2014-05-23 23:11:22 -07:00
|
|
|
type Node interface {
|
2014-07-01 14:50:24 -07:00
|
|
|
Binary
|
|
|
|
Key() Key
|
|
|
|
Value() Value
|
|
|
|
Size() uint64
|
|
|
|
Height() uint8
|
|
|
|
Hash() (ByteSlice, uint64)
|
|
|
|
Save(Db)
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|
|
|
|
|
2014-05-23 23:11:22 -07:00
|
|
|
type Tree interface {
|
2014-07-01 14:50:24 -07:00
|
|
|
Root() Node
|
|
|
|
Size() uint64
|
|
|
|
Height() uint8
|
|
|
|
Has(key Key) bool
|
|
|
|
Get(key Key) Value
|
|
|
|
Hash() (ByteSlice, uint64)
|
|
|
|
Save()
|
2014-07-19 15:19:07 -07:00
|
|
|
Set(Key, Value) bool
|
2014-07-01 14:50:24 -07:00
|
|
|
Remove(Key) (Value, error)
|
|
|
|
Copy() Tree
|
|
|
|
Traverse(func(Node) bool)
|
|
|
|
Values() <-chan Value
|
2014-05-23 23:11:22 -07:00
|
|
|
}
|
2014-05-19 20:46:41 -07:00
|
|
|
|
2014-05-21 16:24:50 -07:00
|
|
|
func NotFound(key Key) error {
|
2014-07-01 14:50:24 -07:00
|
|
|
return fmt.Errorf("Key was not found.")
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|