You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1002 B

11 years ago
11 years ago
11 years ago
11 years ago
  1. package merkle
  2. import (
  3. "os"
  4. "fmt"
  5. )
  6. func PrintIAVLNode(node *IAVLNode) {
  7. fmt.Println("==== NODE")
  8. printIAVLNode(node, 0)
  9. fmt.Println("==== END")
  10. }
  11. func printIAVLNode(node *IAVLNode, indent int) {
  12. indentPrefix := ""
  13. for i:=0; i<indent; i++ {
  14. indentPrefix += " "
  15. }
  16. if node == nil {
  17. fmt.Printf("%s--\n", indentPrefix)
  18. } else {
  19. printIAVLNode(node.leftFilled(nil), indent+1)
  20. fmt.Printf("%s%v:%v\n", indentPrefix, node.key, node.height)
  21. printIAVLNode(node.rightFilled(nil), indent+1)
  22. }
  23. }
  24. func randstr(length int) String {
  25. if urandom, err := os.Open("/dev/urandom"); err != nil {
  26. panic(err)
  27. } else {
  28. slice := make([]byte, length)
  29. if _, err := urandom.Read(slice); err != nil {
  30. panic(err)
  31. }
  32. urandom.Close()
  33. return String(slice)
  34. }
  35. panic("unreachable")
  36. }
  37. func maxUint8(a, b uint8) uint8 {
  38. if a > b {
  39. return a
  40. }
  41. return b
  42. }