github.com/benz9527/xboot@v0.0.0-20240504061247-c23f15593274/lib/infra/ordered_key.go (about)

     1  package infra
     2  
     3  import "cmp"
     4  
     5  type Signed interface {
     6  	~int | ~int8 | ~int16 | ~int32 | ~int64
     7  }
     8  
     9  // Unsigned is a constraint that permits any unsigned integer type.
    10  // If future releases of Go add new predeclared unsigned integer types,
    11  // this constraint will be modified to include them.
    12  type Unsigned interface {
    13  	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
    14  }
    15  
    16  // Integer is a constraint that permits any integer type.
    17  // If future releases of Go add new predeclared integer types,
    18  // this constraint will be modified to include them.
    19  type Integer interface {
    20  	Signed | Unsigned
    21  }
    22  
    23  // Float is a constraint that permits any floating-point type.
    24  // If future releases of Go add new predeclared floating-point types,
    25  // this constraint will be modified to include them.
    26  type Float interface {
    27  	~float32 | ~float64
    28  }
    29  
    30  // Complex is a constraint that permits any complex numeric type.
    31  // If future releases of Go add new predeclared complex numeric types,
    32  // this constraint will be modified to include them.
    33  // We have to calc the complex square root.
    34  // i.e. Amplitude (modulus) comparison in the complex plane.
    35  type Complex interface {
    36  	~complex64 | ~complex128
    37  }
    38  
    39  // OrderedKey
    40  // byte => ~uint8
    41  type OrderedKey interface {
    42  	cmp.Ordered
    43  }
    44  
    45  // OrderedKeyComparator
    46  // Assume i is the new key.
    47  //  1. i == j (i-j == 0, return 0)
    48  //  2. i > j (i-j > 0, return 1), turn to right part.
    49  //  3. i < j (i-j < 0, return -1), turn to left part.
    50  type OrderedKeyComparator[K OrderedKey] func(i, j K) int64