2014-05-19 20:46:41 -07:00
|
|
|
package merkle
|
|
|
|
|
2014-05-20 16:33:10 -07:00
|
|
|
import (
|
2014-05-27 22:31:47 -07:00
|
|
|
"math/big"
|
|
|
|
"crypto/rand"
|
2014-05-20 16:33:10 -07:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func PrintIAVLNode(node *IAVLNode) {
|
|
|
|
fmt.Println("==== NODE")
|
2014-05-27 22:31:47 -07:00
|
|
|
if node != nil {
|
|
|
|
printIAVLNode(node, 0)
|
|
|
|
}
|
2014-05-20 16:33:10 -07:00
|
|
|
fmt.Println("==== END")
|
|
|
|
}
|
|
|
|
|
|
|
|
func printIAVLNode(node *IAVLNode, indent int) {
|
|
|
|
indentPrefix := ""
|
|
|
|
for i:=0; i<indent; i++ {
|
|
|
|
indentPrefix += " "
|
|
|
|
}
|
2014-05-27 22:31:47 -07:00
|
|
|
|
|
|
|
if node.right != nil {
|
2014-05-22 20:28:09 -07:00
|
|
|
printIAVLNode(node.rightFilled(nil), indent+1)
|
2014-05-20 16:33:10 -07:00
|
|
|
}
|
2014-05-27 22:31:47 -07:00
|
|
|
|
|
|
|
fmt.Printf("%s%v:%v\n", indentPrefix, node.key, node.height)
|
|
|
|
|
|
|
|
if node.left != nil {
|
|
|
|
printIAVLNode(node.leftFilled(nil), indent+1)
|
|
|
|
}
|
|
|
|
|
2014-05-20 16:33:10 -07:00
|
|
|
}
|
2014-05-23 17:49:28 -07:00
|
|
|
|
2014-05-27 22:31:47 -07:00
|
|
|
const allRandChars = "0123456789"
|
|
|
|
|
|
|
|
func RandStr(numChars int) String {
|
|
|
|
var res string
|
|
|
|
for i:=0; i<numChars; i++ {
|
|
|
|
v, err := rand.Int(rand.Reader, big.NewInt(int64(10)))
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
randIndex := int(v.Int64())
|
|
|
|
res = res + allRandChars[randIndex:randIndex+1]
|
2014-05-23 17:49:28 -07:00
|
|
|
}
|
2014-05-27 22:31:47 -07:00
|
|
|
return String(res)
|
2014-05-23 17:49:28 -07:00
|
|
|
}
|
|
|
|
|
2014-05-23 23:11:22 -07:00
|
|
|
func maxUint8(a, b uint8) uint8 {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|