2014-05-19 20:46:41 -07:00
|
|
|
package merkle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2014-05-21 16:24:50 -07:00
|
|
|
type Value interface {
|
|
|
|
Bytes() []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type Key interface {
|
|
|
|
Equals(b Key) bool
|
|
|
|
Less(b Key) bool
|
|
|
|
Bytes() []byte
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Tree interface {
|
|
|
|
Root() Node
|
|
|
|
|
|
|
|
Size() int
|
2014-05-21 16:24:50 -07:00
|
|
|
Has(key Key) bool
|
|
|
|
Get(key Key) (value Value, err error)
|
2014-05-21 16:57:30 -07:00
|
|
|
Hash() ([]byte, int)
|
2014-05-19 20:46:41 -07:00
|
|
|
|
2014-05-21 16:24:50 -07:00
|
|
|
Put(key Key, value Value) (err error)
|
|
|
|
Remove(key Key) (value Value, err error)
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Node interface {
|
2014-05-21 16:24:50 -07:00
|
|
|
Key() Key
|
|
|
|
Value() Value
|
|
|
|
Left() Node
|
2014-05-19 20:46:41 -07:00
|
|
|
Right() Node
|
|
|
|
|
|
|
|
Size() int
|
2014-05-21 16:24:50 -07:00
|
|
|
Has(key Key) bool
|
|
|
|
Get(key Key) (value Value, err error)
|
2014-05-21 16:57:30 -07:00
|
|
|
Hash() ([]byte, int)
|
2014-05-20 16:33:10 -07:00
|
|
|
|
2014-05-21 16:24:50 -07:00
|
|
|
Put(key Key, value Value) (_ *IAVLNode, updated bool)
|
|
|
|
Remove(key Key) (_ *IAVLNode, value Value, err error)
|
2014-05-19 20:46:41 -07:00
|
|
|
}
|
|
|
|
|
2014-05-21 19:06:43 -07:00
|
|
|
type NodeIterator func() (node 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.")
|
|
|
|
}
|