github.com/MontFerret/ferret@v0.18.0/pkg/runtime/values/types/helpers.go (about)

     1  package types
     2  
     3  import "github.com/MontFerret/ferret/pkg/runtime/core"
     4  
     5  // Comparison table of builtin types
     6  var typeComparisonTable = map[core.Type]uint64{
     7  	None:     0,
     8  	Boolean:  1,
     9  	Int:      2,
    10  	Float:    3,
    11  	String:   4,
    12  	DateTime: 5,
    13  	Array:    6,
    14  	Object:   7,
    15  	Binary:   8,
    16  }
    17  
    18  func Compare(first, second core.Type) int64 {
    19  	f, ok := typeComparisonTable[first]
    20  
    21  	// custom type
    22  	if !ok {
    23  		return -1
    24  	}
    25  
    26  	s, ok := typeComparisonTable[second]
    27  
    28  	// custom type
    29  	if !ok {
    30  		return 1
    31  	}
    32  
    33  	if f == s {
    34  		return 0
    35  	}
    36  
    37  	if f > s {
    38  		return 1
    39  	}
    40  
    41  	return -1
    42  }