github.com/aergoio/aergo@v1.3.1/pkg/trie/util.go (about)

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