github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/types/comparable.go (about) 1 package types 2 3 // Ordering is the result of a comparison between two values. 4 type Ordering int 5 6 const ( 7 OrderingLess Ordering = iota - 1 8 OrderingEqual 9 OrderingGreater 10 ) 11 12 type Comparable interface{ Compare(o Comparable) Ordering } 13 14 func (i Int) Compare(o Comparable) Ordering { 15 oo := o.(Int) 16 if i < oo { 17 return OrderingLess 18 } else if i > oo { 19 return OrderingGreater 20 } 21 return OrderingEqual 22 } 23 24 func (i Int64) Compare(o Comparable) Ordering { 25 oo := o.(Int64) 26 if i < oo { 27 return OrderingLess 28 } else if i > oo { 29 return OrderingGreater 30 } 31 return OrderingEqual 32 } 33 34 func (i Int32) Compare(o Comparable) Ordering { 35 oo := o.(Int32) 36 if i < oo { 37 return OrderingLess 38 } else if i > oo { 39 return OrderingGreater 40 } 41 return OrderingEqual 42 } 43 44 func (i Int16) Compare(o Comparable) Ordering { 45 oo := o.(Int16) 46 if i < oo { 47 return OrderingLess 48 } else if i > oo { 49 return OrderingGreater 50 } 51 return OrderingEqual 52 } 53 54 func (i Int8) Compare(o Comparable) Ordering { 55 oo := o.(Int8) 56 if i < oo { 57 return OrderingLess 58 } else if i > oo { 59 return OrderingGreater 60 } 61 return OrderingEqual 62 } 63 64 func (i Uint) Compare(o Comparable) Ordering { 65 oo := o.(Uint) 66 if i < oo { 67 return OrderingLess 68 } else if i > oo { 69 return OrderingGreater 70 } 71 return OrderingEqual 72 } 73 74 func (i Uint64) Compare(o Comparable) Ordering { 75 oo := o.(Uint64) 76 if i < oo { 77 return OrderingLess 78 } else if i > oo { 79 return OrderingGreater 80 } 81 return OrderingEqual 82 } 83 84 func (i Uint32) Compare(o Comparable) Ordering { 85 oo := o.(Uint32) 86 if i < oo { 87 return OrderingLess 88 } else if i > oo { 89 return OrderingGreater 90 } 91 return OrderingEqual 92 } 93 94 func (i Uint16) Compare(o Comparable) Ordering { 95 oo := o.(Uint16) 96 if i < oo { 97 return OrderingLess 98 } else if i > oo { 99 return OrderingGreater 100 } 101 return OrderingEqual 102 } 103 104 func (i Uint8) Compare(o Comparable) Ordering { 105 oo := o.(Uint8) 106 if i < oo { 107 return OrderingLess 108 } else if i > oo { 109 return OrderingGreater 110 } 111 return OrderingEqual 112 } 113 114 func (i String) Compare(o Comparable) Ordering { 115 oo := o.(String) 116 if i < oo { 117 return OrderingLess 118 } else if i > oo { 119 return OrderingGreater 120 } 121 return OrderingEqual 122 }