2014-05-19 20:46:41 -07:00
|
|
|
package merkle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2014-05-21 16:24:50 -07:00
|
|
|
type Value interface {
|
2014-05-21 21:48:41 -07:00
|
|
|
Bytes() []byte
|
2014-05-21 16:24:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Key interface {
|
2014-05-21 21:48:41 -07:00
|
|
|
Equals(b Key) bool
|
|
|
|
Less(b Key) bool
|
|
|
|
Bytes() []byte
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Tree interface {
|
2014-05-21 21:48:41 -07:00
|
|
|
Root() Node
|
2014-05-19 20:46:41 -07:00
|
|
|
|
2014-05-21 21:48:41 -07:00
|
|
|
Size() uint64
|
|
|
|
Height() uint8
|
|
|
|
Has(key Key) bool
|
|
|
|
Get(key Key) (Value, error)
|
|
|
|
Hash() ([]byte, uint64)
|
2014-05-19 20:46:41 -07:00
|
|
|
|
2014-05-21 21:48:41 -07:00
|
|
|
Put(Key, Value) (err error)
|
|
|
|
Remove(Key) (Value, error)
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Node interface {
|
2014-05-21 21:48:41 -07:00
|
|
|
Key() Key
|
|
|
|
Value() Value
|
|
|
|
Left() Node
|
|
|
|
Right() Node
|
|
|
|
|
|
|
|
Size() uint64
|
|
|
|
Height() uint8
|
|
|
|
Has(Key) bool
|
|
|
|
Get(Key) (Value, error)
|
|
|
|
Hash() ([]byte, uint64)
|
|
|
|
Bytes() []byte
|
|
|
|
|
|
|
|
Put(Key, Value) (*IAVLNode, bool)
|
|
|
|
Remove(Key) (*IAVLNode, Value, error)
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|
|
|
|
|
2014-05-21 21:48:41 -07:00
|
|
|
type NodeIterator func() Node
|
2014-05-19 20:46:41 -07:00
|
|
|
|
2014-05-21 16:24:50 -07:00
|
|
|
func NotFound(key Key) error {
|
2014-05-19 20:46:41 -07:00
|
|
|
return fmt.Errorf("Key was not found.")
|
|
|
|
}
|