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.

42 lines
640 B

  1. /**
  2. * @file
  3. * @copyright defined in aergo/LICENSE.txt
  4. */
  5. package trie
  6. import (
  7. "bytes"
  8. )
  9. var (
  10. // Trie default value : [byte(0)]
  11. DefaultLeaf = []byte{0}
  12. )
  13. const (
  14. HashLength = 32
  15. maxPastTries = 300
  16. )
  17. type Hash [HashLength]byte
  18. func bitIsSet(bits []byte, i int) bool {
  19. return bits[i/8]&(1<<uint(7-i%8)) != 0
  20. }
  21. func bitSet(bits []byte, i int) {
  22. bits[i/8] |= 1 << uint(7-i%8)
  23. }
  24. // for sorting test data
  25. type DataArray [][]byte
  26. func (d DataArray) Len() int {
  27. return len(d)
  28. }
  29. func (d DataArray) Swap(i, j int) {
  30. d[i], d[j] = d[j], d[i]
  31. }
  32. func (d DataArray) Less(i, j int) bool {
  33. return bytes.Compare(d[i], d[j]) == -1
  34. }