diff --git a/tlb/address.go b/tlb/address.go index 13ee674d..db8ea937 100644 --- a/tlb/address.go +++ b/tlb/address.go @@ -1,6 +1,7 @@ package tlb import ( + "bytes" "fmt" "github.com/tonkeeper/tongo/boc" @@ -21,6 +22,14 @@ func (addr AddressWithWorkchain) Equal(other any) bool { return addr.Workchain == otherAddr.Workchain && addr.Address == otherAddr.Address } +func (addr AddressWithWorkchain) Compare(other any) (int, bool) { + otherAddr, ok := other.(AddressWithWorkchain) + if !ok { + return 0, false + } + return bytes.Compare(addr.Address[:], otherAddr.Address[:]), true +} + func (addr AddressWithWorkchain) FixedSize() int { return 288 } diff --git a/tlb/generator.go b/tlb/generator.go index fcb68cb9..95bf9380 100644 --- a/tlb/generator.go +++ b/tlb/generator.go @@ -25,11 +25,12 @@ func main() { // Code autogenerated. DO NOT EDIT. import ( + "bytes" "encoding/hex" "fmt" "math/big" - "strings" "strconv" + "strings" "github.com/tonkeeper/tongo/boc" ) diff --git a/tlb/hashmap.go b/tlb/hashmap.go index a9a9515e..3e9f27d3 100644 --- a/tlb/hashmap.go +++ b/tlb/hashmap.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "slices" "strings" "github.com/tonkeeper/tongo/boc" @@ -12,6 +13,7 @@ import ( type fixedSize interface { FixedSize() int Equal(other any) bool + Compare(other any) (int, bool) } // HashmapItem represents a key-value pair stored in HashmapE[T]. @@ -323,8 +325,23 @@ func (h *Hashmap[keyT, T]) Put(key keyT, value T) { return } } - h.values = append(h.values, value) - h.keys = append(h.keys, key) //todo: i think we need to sort keys + + index := len(h.keys) + for idx, other := range h.keys { + cmp, ok := key.Compare(other) + if !ok { + // only happens when the user implements their own + // fixedSize interface and intentionally returns false + panic("key type mismatch") + } + if cmp < 0 { + index = idx + break + } + } + + h.keys = slices.Insert(h.keys, index, key) + h.values = slices.Insert(h.values, index, value) } type HashmapE[keyT fixedSize, T any] struct { diff --git a/tlb/integers.go b/tlb/integers.go index 750c06a4..b843a456 100644 --- a/tlb/integers.go +++ b/tlb/integers.go @@ -1,8 +1,8 @@ package tlb - -// Code autogenerated. DO NOT EDIT. +// Code autogenerated. DO NOT EDIT. import ( + "bytes" "encoding/hex" "fmt" "math/big" @@ -1315,6 +1315,20 @@ func (u Uint1) Equal(other any) bool { } return u == otherInt } + +func (u Uint1) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint1) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint1) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1351,6 +1365,20 @@ func (u Int1) Equal(other any) bool { } return u == otherInt } + +func (u Int1) Compare(other any) (int, bool) { + otherInt, ok := other.(Int1) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int1) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1387,6 +1415,20 @@ func (u Uint2) Equal(other any) bool { } return u == otherInt } + +func (u Uint2) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint2) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint2) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1423,6 +1465,20 @@ func (u Int2) Equal(other any) bool { } return u == otherInt } + +func (u Int2) Compare(other any) (int, bool) { + otherInt, ok := other.(Int2) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int2) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1459,6 +1515,20 @@ func (u Uint3) Equal(other any) bool { } return u == otherInt } + +func (u Uint3) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint3) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint3) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1495,6 +1565,20 @@ func (u Int3) Equal(other any) bool { } return u == otherInt } + +func (u Int3) Compare(other any) (int, bool) { + otherInt, ok := other.(Int3) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int3) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1531,6 +1615,20 @@ func (u Uint4) Equal(other any) bool { } return u == otherInt } + +func (u Uint4) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint4) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint4) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1567,6 +1665,20 @@ func (u Int4) Equal(other any) bool { } return u == otherInt } + +func (u Int4) Compare(other any) (int, bool) { + otherInt, ok := other.(Int4) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int4) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1603,6 +1715,20 @@ func (u Uint5) Equal(other any) bool { } return u == otherInt } + +func (u Uint5) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint5) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint5) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1639,6 +1765,20 @@ func (u Int5) Equal(other any) bool { } return u == otherInt } + +func (u Int5) Compare(other any) (int, bool) { + otherInt, ok := other.(Int5) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int5) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1675,6 +1815,20 @@ func (u Uint6) Equal(other any) bool { } return u == otherInt } + +func (u Uint6) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint6) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint6) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1711,6 +1865,20 @@ func (u Int6) Equal(other any) bool { } return u == otherInt } + +func (u Int6) Compare(other any) (int, bool) { + otherInt, ok := other.(Int6) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int6) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1747,6 +1915,20 @@ func (u Uint7) Equal(other any) bool { } return u == otherInt } + +func (u Uint7) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint7) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint7) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1783,6 +1965,20 @@ func (u Int7) Equal(other any) bool { } return u == otherInt } + +func (u Int7) Compare(other any) (int, bool) { + otherInt, ok := other.(Int7) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int7) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1819,6 +2015,20 @@ func (u Uint8) Equal(other any) bool { } return u == otherInt } + +func (u Uint8) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint8) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint8) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1855,6 +2065,20 @@ func (u Int8) Equal(other any) bool { } return u == otherInt } + +func (u Int8) Compare(other any) (int, bool) { + otherInt, ok := other.(Int8) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int8) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1891,6 +2115,20 @@ func (u Uint9) Equal(other any) bool { } return u == otherInt } + +func (u Uint9) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint9) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint9) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1927,6 +2165,20 @@ func (u Int9) Equal(other any) bool { } return u == otherInt } + +func (u Int9) Compare(other any) (int, bool) { + otherInt, ok := other.(Int9) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int9) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1963,6 +2215,20 @@ func (u Uint10) Equal(other any) bool { } return u == otherInt } + +func (u Uint10) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint10) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint10) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -1999,6 +2265,20 @@ func (u Int10) Equal(other any) bool { } return u == otherInt } + +func (u Int10) Compare(other any) (int, bool) { + otherInt, ok := other.(Int10) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int10) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2035,6 +2315,20 @@ func (u Uint11) Equal(other any) bool { } return u == otherInt } + +func (u Uint11) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint11) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint11) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2071,6 +2365,20 @@ func (u Int11) Equal(other any) bool { } return u == otherInt } + +func (u Int11) Compare(other any) (int, bool) { + otherInt, ok := other.(Int11) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int11) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2107,6 +2415,20 @@ func (u Uint12) Equal(other any) bool { } return u == otherInt } + +func (u Uint12) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint12) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint12) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2143,6 +2465,20 @@ func (u Int12) Equal(other any) bool { } return u == otherInt } + +func (u Int12) Compare(other any) (int, bool) { + otherInt, ok := other.(Int12) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int12) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2179,6 +2515,20 @@ func (u Uint13) Equal(other any) bool { } return u == otherInt } + +func (u Uint13) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint13) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint13) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2215,6 +2565,20 @@ func (u Int13) Equal(other any) bool { } return u == otherInt } + +func (u Int13) Compare(other any) (int, bool) { + otherInt, ok := other.(Int13) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int13) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2251,6 +2615,20 @@ func (u Uint14) Equal(other any) bool { } return u == otherInt } + +func (u Uint14) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint14) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint14) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2287,6 +2665,20 @@ func (u Int14) Equal(other any) bool { } return u == otherInt } + +func (u Int14) Compare(other any) (int, bool) { + otherInt, ok := other.(Int14) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int14) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2323,6 +2715,20 @@ func (u Uint15) Equal(other any) bool { } return u == otherInt } + +func (u Uint15) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint15) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint15) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2359,6 +2765,20 @@ func (u Int15) Equal(other any) bool { } return u == otherInt } + +func (u Int15) Compare(other any) (int, bool) { + otherInt, ok := other.(Int15) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int15) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2395,6 +2815,20 @@ func (u Uint16) Equal(other any) bool { } return u == otherInt } + +func (u Uint16) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint16) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint16) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2431,6 +2865,20 @@ func (u Int16) Equal(other any) bool { } return u == otherInt } + +func (u Int16) Compare(other any) (int, bool) { + otherInt, ok := other.(Int16) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int16) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2467,6 +2915,20 @@ func (u Uint17) Equal(other any) bool { } return u == otherInt } + +func (u Uint17) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint17) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint17) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2503,6 +2965,20 @@ func (u Int17) Equal(other any) bool { } return u == otherInt } + +func (u Int17) Compare(other any) (int, bool) { + otherInt, ok := other.(Int17) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int17) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2539,6 +3015,20 @@ func (u Uint18) Equal(other any) bool { } return u == otherInt } + +func (u Uint18) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint18) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint18) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2575,6 +3065,20 @@ func (u Int18) Equal(other any) bool { } return u == otherInt } + +func (u Int18) Compare(other any) (int, bool) { + otherInt, ok := other.(Int18) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int18) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2611,9 +3115,23 @@ func (u Uint19) Equal(other any) bool { } return u == otherInt } -func (u Uint19) MarshalJSON() ([]byte, error) { - return []byte(fmt.Sprintf("%d", u)), nil -} + +func (u Uint19) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint19) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} +func (u Uint19) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf("%d", u)), nil +} func (u *Uint19) UnmarshalJSON(p []byte) error { value, err := strconv.ParseUint(strings.Trim(string(p), "\""), 10, 19) @@ -2647,6 +3165,20 @@ func (u Int19) Equal(other any) bool { } return u == otherInt } + +func (u Int19) Compare(other any) (int, bool) { + otherInt, ok := other.(Int19) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int19) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2683,6 +3215,20 @@ func (u Uint20) Equal(other any) bool { } return u == otherInt } + +func (u Uint20) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint20) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint20) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2719,6 +3265,20 @@ func (u Int20) Equal(other any) bool { } return u == otherInt } + +func (u Int20) Compare(other any) (int, bool) { + otherInt, ok := other.(Int20) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int20) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2755,6 +3315,20 @@ func (u Uint21) Equal(other any) bool { } return u == otherInt } + +func (u Uint21) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint21) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint21) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2791,6 +3365,20 @@ func (u Int21) Equal(other any) bool { } return u == otherInt } + +func (u Int21) Compare(other any) (int, bool) { + otherInt, ok := other.(Int21) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int21) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2827,6 +3415,20 @@ func (u Uint22) Equal(other any) bool { } return u == otherInt } + +func (u Uint22) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint22) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint22) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2863,6 +3465,20 @@ func (u Int22) Equal(other any) bool { } return u == otherInt } + +func (u Int22) Compare(other any) (int, bool) { + otherInt, ok := other.(Int22) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int22) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2899,6 +3515,20 @@ func (u Uint23) Equal(other any) bool { } return u == otherInt } + +func (u Uint23) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint23) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint23) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2935,6 +3565,20 @@ func (u Int23) Equal(other any) bool { } return u == otherInt } + +func (u Int23) Compare(other any) (int, bool) { + otherInt, ok := other.(Int23) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int23) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -2971,6 +3615,20 @@ func (u Uint24) Equal(other any) bool { } return u == otherInt } + +func (u Uint24) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint24) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint24) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3007,6 +3665,20 @@ func (u Int24) Equal(other any) bool { } return u == otherInt } + +func (u Int24) Compare(other any) (int, bool) { + otherInt, ok := other.(Int24) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int24) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3043,6 +3715,20 @@ func (u Uint25) Equal(other any) bool { } return u == otherInt } + +func (u Uint25) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint25) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint25) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3079,6 +3765,20 @@ func (u Int25) Equal(other any) bool { } return u == otherInt } + +func (u Int25) Compare(other any) (int, bool) { + otherInt, ok := other.(Int25) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int25) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3115,6 +3815,20 @@ func (u Uint26) Equal(other any) bool { } return u == otherInt } + +func (u Uint26) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint26) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint26) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3151,6 +3865,20 @@ func (u Int26) Equal(other any) bool { } return u == otherInt } + +func (u Int26) Compare(other any) (int, bool) { + otherInt, ok := other.(Int26) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int26) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3187,6 +3915,20 @@ func (u Uint27) Equal(other any) bool { } return u == otherInt } + +func (u Uint27) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint27) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint27) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3223,6 +3965,20 @@ func (u Int27) Equal(other any) bool { } return u == otherInt } + +func (u Int27) Compare(other any) (int, bool) { + otherInt, ok := other.(Int27) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int27) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3259,6 +4015,20 @@ func (u Uint28) Equal(other any) bool { } return u == otherInt } + +func (u Uint28) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint28) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint28) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3295,6 +4065,20 @@ func (u Int28) Equal(other any) bool { } return u == otherInt } + +func (u Int28) Compare(other any) (int, bool) { + otherInt, ok := other.(Int28) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int28) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3331,6 +4115,20 @@ func (u Uint29) Equal(other any) bool { } return u == otherInt } + +func (u Uint29) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint29) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint29) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3367,6 +4165,20 @@ func (u Int29) Equal(other any) bool { } return u == otherInt } + +func (u Int29) Compare(other any) (int, bool) { + otherInt, ok := other.(Int29) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int29) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3403,6 +4215,20 @@ func (u Uint30) Equal(other any) bool { } return u == otherInt } + +func (u Uint30) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint30) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint30) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3439,6 +4265,20 @@ func (u Int30) Equal(other any) bool { } return u == otherInt } + +func (u Int30) Compare(other any) (int, bool) { + otherInt, ok := other.(Int30) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int30) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3475,6 +4315,20 @@ func (u Uint31) Equal(other any) bool { } return u == otherInt } + +func (u Uint31) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint31) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint31) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3511,6 +4365,20 @@ func (u Int31) Equal(other any) bool { } return u == otherInt } + +func (u Int31) Compare(other any) (int, bool) { + otherInt, ok := other.(Int31) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int31) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3547,6 +4415,20 @@ func (u Uint32) Equal(other any) bool { } return u == otherInt } + +func (u Uint32) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint32) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint32) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3583,6 +4465,20 @@ func (u Int32) Equal(other any) bool { } return u == otherInt } + +func (u Int32) Compare(other any) (int, bool) { + otherInt, ok := other.(Int32) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int32) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3619,6 +4515,20 @@ func (u Uint33) Equal(other any) bool { } return u == otherInt } + +func (u Uint33) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint33) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint33) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3655,6 +4565,20 @@ func (u Int33) Equal(other any) bool { } return u == otherInt } + +func (u Int33) Compare(other any) (int, bool) { + otherInt, ok := other.(Int33) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int33) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3691,6 +4615,20 @@ func (u Uint34) Equal(other any) bool { } return u == otherInt } + +func (u Uint34) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint34) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint34) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3727,6 +4665,20 @@ func (u Int34) Equal(other any) bool { } return u == otherInt } + +func (u Int34) Compare(other any) (int, bool) { + otherInt, ok := other.(Int34) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int34) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3763,6 +4715,20 @@ func (u Uint35) Equal(other any) bool { } return u == otherInt } + +func (u Uint35) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint35) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint35) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3799,6 +4765,20 @@ func (u Int35) Equal(other any) bool { } return u == otherInt } + +func (u Int35) Compare(other any) (int, bool) { + otherInt, ok := other.(Int35) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int35) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3835,6 +4815,20 @@ func (u Uint36) Equal(other any) bool { } return u == otherInt } + +func (u Uint36) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint36) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint36) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3871,6 +4865,20 @@ func (u Int36) Equal(other any) bool { } return u == otherInt } + +func (u Int36) Compare(other any) (int, bool) { + otherInt, ok := other.(Int36) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int36) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3907,6 +4915,20 @@ func (u Uint37) Equal(other any) bool { } return u == otherInt } + +func (u Uint37) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint37) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint37) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3943,6 +4965,20 @@ func (u Int37) Equal(other any) bool { } return u == otherInt } + +func (u Int37) Compare(other any) (int, bool) { + otherInt, ok := other.(Int37) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int37) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -3979,6 +5015,20 @@ func (u Uint38) Equal(other any) bool { } return u == otherInt } + +func (u Uint38) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint38) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint38) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4015,6 +5065,20 @@ func (u Int38) Equal(other any) bool { } return u == otherInt } + +func (u Int38) Compare(other any) (int, bool) { + otherInt, ok := other.(Int38) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int38) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4051,6 +5115,20 @@ func (u Uint39) Equal(other any) bool { } return u == otherInt } + +func (u Uint39) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint39) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint39) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4087,6 +5165,20 @@ func (u Int39) Equal(other any) bool { } return u == otherInt } + +func (u Int39) Compare(other any) (int, bool) { + otherInt, ok := other.(Int39) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int39) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4123,6 +5215,20 @@ func (u Uint40) Equal(other any) bool { } return u == otherInt } + +func (u Uint40) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint40) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint40) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4159,6 +5265,20 @@ func (u Int40) Equal(other any) bool { } return u == otherInt } + +func (u Int40) Compare(other any) (int, bool) { + otherInt, ok := other.(Int40) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int40) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4195,6 +5315,20 @@ func (u Uint41) Equal(other any) bool { } return u == otherInt } + +func (u Uint41) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint41) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint41) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4231,6 +5365,20 @@ func (u Int41) Equal(other any) bool { } return u == otherInt } + +func (u Int41) Compare(other any) (int, bool) { + otherInt, ok := other.(Int41) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int41) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4267,6 +5415,20 @@ func (u Uint42) Equal(other any) bool { } return u == otherInt } + +func (u Uint42) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint42) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint42) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4303,6 +5465,20 @@ func (u Int42) Equal(other any) bool { } return u == otherInt } + +func (u Int42) Compare(other any) (int, bool) { + otherInt, ok := other.(Int42) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int42) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4339,6 +5515,20 @@ func (u Uint43) Equal(other any) bool { } return u == otherInt } + +func (u Uint43) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint43) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint43) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4375,6 +5565,20 @@ func (u Int43) Equal(other any) bool { } return u == otherInt } + +func (u Int43) Compare(other any) (int, bool) { + otherInt, ok := other.(Int43) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int43) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4411,6 +5615,20 @@ func (u Uint44) Equal(other any) bool { } return u == otherInt } + +func (u Uint44) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint44) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint44) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4447,6 +5665,20 @@ func (u Int44) Equal(other any) bool { } return u == otherInt } + +func (u Int44) Compare(other any) (int, bool) { + otherInt, ok := other.(Int44) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int44) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4483,6 +5715,20 @@ func (u Uint45) Equal(other any) bool { } return u == otherInt } + +func (u Uint45) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint45) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint45) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4519,6 +5765,20 @@ func (u Int45) Equal(other any) bool { } return u == otherInt } + +func (u Int45) Compare(other any) (int, bool) { + otherInt, ok := other.(Int45) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int45) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4555,6 +5815,20 @@ func (u Uint46) Equal(other any) bool { } return u == otherInt } + +func (u Uint46) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint46) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint46) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4591,6 +5865,20 @@ func (u Int46) Equal(other any) bool { } return u == otherInt } + +func (u Int46) Compare(other any) (int, bool) { + otherInt, ok := other.(Int46) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int46) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4627,6 +5915,20 @@ func (u Uint47) Equal(other any) bool { } return u == otherInt } + +func (u Uint47) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint47) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint47) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4663,6 +5965,20 @@ func (u Int47) Equal(other any) bool { } return u == otherInt } + +func (u Int47) Compare(other any) (int, bool) { + otherInt, ok := other.(Int47) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int47) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4699,6 +6015,20 @@ func (u Uint48) Equal(other any) bool { } return u == otherInt } + +func (u Uint48) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint48) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint48) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4735,6 +6065,20 @@ func (u Int48) Equal(other any) bool { } return u == otherInt } + +func (u Int48) Compare(other any) (int, bool) { + otherInt, ok := other.(Int48) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int48) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4767,9 +6111,23 @@ func (u Uint49) FixedSize() int { func (u Uint49) Equal(other any) bool { otherInt, ok := other.(Uint49) if !ok { - return false + return false + } + return u == otherInt +} + +func (u Uint49) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint49) + if !ok { + return 0, false } - return u == otherInt + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true } func (u Uint49) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil @@ -4807,6 +6165,20 @@ func (u Int49) Equal(other any) bool { } return u == otherInt } + +func (u Int49) Compare(other any) (int, bool) { + otherInt, ok := other.(Int49) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int49) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4843,6 +6215,20 @@ func (u Uint50) Equal(other any) bool { } return u == otherInt } + +func (u Uint50) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint50) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint50) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4879,6 +6265,20 @@ func (u Int50) Equal(other any) bool { } return u == otherInt } + +func (u Int50) Compare(other any) (int, bool) { + otherInt, ok := other.(Int50) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int50) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4915,6 +6315,20 @@ func (u Uint51) Equal(other any) bool { } return u == otherInt } + +func (u Uint51) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint51) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint51) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4951,6 +6365,20 @@ func (u Int51) Equal(other any) bool { } return u == otherInt } + +func (u Int51) Compare(other any) (int, bool) { + otherInt, ok := other.(Int51) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int51) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -4987,6 +6415,20 @@ func (u Uint52) Equal(other any) bool { } return u == otherInt } + +func (u Uint52) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint52) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint52) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5023,6 +6465,20 @@ func (u Int52) Equal(other any) bool { } return u == otherInt } + +func (u Int52) Compare(other any) (int, bool) { + otherInt, ok := other.(Int52) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int52) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5059,6 +6515,20 @@ func (u Uint53) Equal(other any) bool { } return u == otherInt } + +func (u Uint53) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint53) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint53) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5095,6 +6565,20 @@ func (u Int53) Equal(other any) bool { } return u == otherInt } + +func (u Int53) Compare(other any) (int, bool) { + otherInt, ok := other.(Int53) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int53) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5131,6 +6615,20 @@ func (u Uint54) Equal(other any) bool { } return u == otherInt } + +func (u Uint54) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint54) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint54) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5167,6 +6665,20 @@ func (u Int54) Equal(other any) bool { } return u == otherInt } + +func (u Int54) Compare(other any) (int, bool) { + otherInt, ok := other.(Int54) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int54) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5203,6 +6715,20 @@ func (u Uint55) Equal(other any) bool { } return u == otherInt } + +func (u Uint55) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint55) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint55) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5239,6 +6765,20 @@ func (u Int55) Equal(other any) bool { } return u == otherInt } + +func (u Int55) Compare(other any) (int, bool) { + otherInt, ok := other.(Int55) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int55) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5275,6 +6815,20 @@ func (u Uint56) Equal(other any) bool { } return u == otherInt } + +func (u Uint56) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint56) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint56) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5311,6 +6865,20 @@ func (u Int56) Equal(other any) bool { } return u == otherInt } + +func (u Int56) Compare(other any) (int, bool) { + otherInt, ok := other.(Int56) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int56) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil } @@ -5347,6 +6915,20 @@ func (u Uint57) Equal(other any) bool { } return u == otherInt } + +func (u Uint57) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint57) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint57) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5383,6 +6965,20 @@ func (u Int57) Equal(other any) bool { } return u == otherInt } + +func (u Int57) Compare(other any) (int, bool) { + otherInt, ok := other.(Int57) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int57) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5419,6 +7015,20 @@ func (u Uint58) Equal(other any) bool { } return u == otherInt } + +func (u Uint58) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint58) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint58) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5455,6 +7065,20 @@ func (u Int58) Equal(other any) bool { } return u == otherInt } + +func (u Int58) Compare(other any) (int, bool) { + otherInt, ok := other.(Int58) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int58) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5491,6 +7115,20 @@ func (u Uint59) Equal(other any) bool { } return u == otherInt } + +func (u Uint59) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint59) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint59) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5527,6 +7165,20 @@ func (u Int59) Equal(other any) bool { } return u == otherInt } + +func (u Int59) Compare(other any) (int, bool) { + otherInt, ok := other.(Int59) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int59) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5563,6 +7215,20 @@ func (u Uint60) Equal(other any) bool { } return u == otherInt } + +func (u Uint60) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint60) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint60) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5599,6 +7265,20 @@ func (u Int60) Equal(other any) bool { } return u == otherInt } + +func (u Int60) Compare(other any) (int, bool) { + otherInt, ok := other.(Int60) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int60) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5635,6 +7315,20 @@ func (u Uint61) Equal(other any) bool { } return u == otherInt } + +func (u Uint61) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint61) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint61) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5671,6 +7365,20 @@ func (u Int61) Equal(other any) bool { } return u == otherInt } + +func (u Int61) Compare(other any) (int, bool) { + otherInt, ok := other.(Int61) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int61) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5707,6 +7415,20 @@ func (u Uint62) Equal(other any) bool { } return u == otherInt } + +func (u Uint62) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint62) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint62) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5743,6 +7465,20 @@ func (u Int62) Equal(other any) bool { } return u == otherInt } + +func (u Int62) Compare(other any) (int, bool) { + otherInt, ok := other.(Int62) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int62) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5779,6 +7515,20 @@ func (u Uint63) Equal(other any) bool { } return u == otherInt } + +func (u Uint63) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint63) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint63) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5815,6 +7565,20 @@ func (u Int63) Equal(other any) bool { } return u == otherInt } + +func (u Int63) Compare(other any) (int, bool) { + otherInt, ok := other.(Int63) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int63) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5851,6 +7615,20 @@ func (u Uint64) Equal(other any) bool { } return u == otherInt } + +func (u Uint64) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint64) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Uint64) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -5887,6 +7665,20 @@ func (u Int64) Equal(other any) bool { } return u == otherInt } + +func (u Int64) Compare(other any) (int, bool) { + otherInt, ok := other.(Int64) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} func (u Int64) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("\"%d\"", u)), nil } @@ -6140,6 +7932,14 @@ func (u Bits80) Equal(other any) bool { return u == otherBits } +func (u Bits80) Compare(other any) (int, bool) { + otherBits, ok := other.(Bits80) + if !ok { + return 0, false + } + return bytes.Compare(u[:], otherBits[:]), true +} + type Bits96 [12]byte func (u Bits96) FixedSize() int { @@ -6170,6 +7970,14 @@ func (u Bits96) Equal(other any) bool { return u == otherBits } +func (u Bits96) Compare(other any) (int, bool) { + otherBits, ok := other.(Bits96) + if !ok { + return 0, false + } + return bytes.Compare(u[:], otherBits[:]), true +} + type Bits256 [32]byte func (u Bits256) FixedSize() int { @@ -6200,6 +8008,14 @@ func (u Bits256) Equal(other any) bool { return u == otherBits } +func (u Bits256) Compare(other any) (int, bool) { + otherBits, ok := other.(Bits256) + if !ok { + return 0, false + } + return bytes.Compare(u[:], otherBits[:]), true +} + type Bits264 [33]byte func (u Bits264) FixedSize() int { @@ -6230,6 +8046,14 @@ func (u Bits264) Equal(other any) bool { return u == otherBits } +func (u Bits264) Compare(other any) (int, bool) { + otherBits, ok := other.(Bits264) + if !ok { + return 0, false + } + return bytes.Compare(u[:], otherBits[:]), true +} + type Bits320 [40]byte func (u Bits320) FixedSize() int { @@ -6260,6 +8084,14 @@ func (u Bits320) Equal(other any) bool { return u == otherBits } +func (u Bits320) Compare(other any) (int, bool) { + otherBits, ok := other.(Bits320) + if !ok { + return 0, false + } + return bytes.Compare(u[:], otherBits[:]), true +} + type Bits352 [44]byte func (u Bits352) FixedSize() int { @@ -6290,6 +8122,14 @@ func (u Bits352) Equal(other any) bool { return u == otherBits } +func (u Bits352) Compare(other any) (int, bool) { + otherBits, ok := other.(Bits352) + if !ok { + return 0, false + } + return bytes.Compare(u[:], otherBits[:]), true +} + type Bits512 [64]byte func (u Bits512) FixedSize() int { @@ -6319,3 +8159,12 @@ func (u Bits512) Equal(other any) bool { } return u == otherBits } + +func (u Bits512) Compare(other any) (int, bool) { + otherBits, ok := other.(Bits512) + if !ok { + return 0, false + } + return bytes.Compare(u[:], otherBits[:]), true +} + \ No newline at end of file diff --git a/tlb/parser/builtin_generator.go b/tlb/parser/builtin_generator.go index bf5c4930..1f807c11 100644 --- a/tlb/parser/builtin_generator.go +++ b/tlb/parser/builtin_generator.go @@ -9,7 +9,7 @@ import ( func GenerateVarUintTypes(max int) string { var b bytes.Buffer - templateStr := ` + templateStr := ` type VarUInteger{{.NameIndex}} big.Int func (u VarUInteger{{.NameIndex}}) MarshalTLB(c *boc.Cell, encoder *Encoder) error { @@ -98,6 +98,20 @@ func (u Uint{{.NameIndex}}) Equal(other any) bool { return u == otherInt } +func (u Uint{{.NameIndex}}) Compare(other any) (int, bool) { + otherInt, ok := other.(Uint{{.NameIndex}}) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} + {{- if lt .NameIndex 57 }} func (u Uint{{.NameIndex}}) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil @@ -141,6 +155,20 @@ func (u Int{{.NameIndex}}) Equal(other any) bool { return u == otherInt } +func (u Int{{.NameIndex}}) Compare(other any) (int, bool) { + otherInt, ok := other.(Int{{.NameIndex}}) + if !ok { + return 0, false + } + if u == otherInt { + return 0, true + } + if u < otherInt { + return -1, true + } + return 1, true +} + {{- if lt .NameIndex 57 }} func (u Int{{.NameIndex}}) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%d", u)), nil @@ -310,7 +338,15 @@ func (u Bits%v) Equal(other any) bool { } return u == otherBits } - `, i, i/8, i, i, i, i, i/8, i, i, i) + +func (u Bits%v) Compare(other any) (int, bool) { + otherBits, ok := other.(Bits%v) + if !ok { + return 0, false + } + return bytes.Compare(u[:], otherBits[:]), true +} + `, i, i/8, i, i, i, i, i/8, i, i, i, i, i) } else { fmt.Fprintf(&b, ` type Bits%v boc.BitString