15 func (w Word256) String() string { return string(w[:]) }
16 func (w Word256) TrimmedString() string { return TrimmedString(w.Bytes()) }
17 func (w Word256) Copy() Word256 { return w }
18 func (w Word256) Bytes() []byte { return w[:] } // copied.
19 func (w Word256) Prefix(n int) []byte { return w[:n] }
20 func (w Word256) Postfix(n int) []byte { return w[32-n:] }
21 func (w Word256) IsZero() bool {
23 for _, byt := range w {
28 func (w Word256) Compare(other Word256) int {
29 return bytes.Compare(w[:], other[:])
32 func Uint64ToWord256(i uint64) Word256 {
34 PutUint64BE(buf[:], i)
35 return LeftPadWord256(buf[:])
38 func Int64ToWord256(i int64) Word256 {
41 return LeftPadWord256(buf[:])
44 func RightPadWord256(bz []byte) (word Word256) {
49 func LeftPadWord256(bz []byte) (word Word256) {
50 copy(word[32-len(bz):], bz)
54 func Uint64FromWord256(word Word256) uint64 {
55 buf := word.Postfix(8)
56 return GetUint64BE(buf)
59 func Int64FromWord256(word Word256) int64 {
60 buf := word.Postfix(8)
61 return GetInt64BE(buf)
64 //-------------------------------------
66 type Tuple256 struct {
71 func (tuple Tuple256) Compare(other Tuple256) int {
72 firstCompare := tuple.First.Compare(other.First)
73 if firstCompare == 0 {
74 return tuple.Second.Compare(other.Second)
80 func Tuple256Split(t Tuple256) (Word256, Word256) {
81 return t.First, t.Second
84 type Tuple256Slice []Tuple256
86 func (p Tuple256Slice) Len() int { return len(p) }
87 func (p Tuple256Slice) Less(i, j int) bool {
88 return p[i].Compare(p[j]) < 0
90 func (p Tuple256Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
91 func (p Tuple256Slice) Sort() { sort.Sort(p) }