...
  
  
     1  
    18  
    19  package utils
    20  
    21  import "fmt"
    22  
    23  func MaxOfArrayFloat(array []float64) (float64, int) {
    24  	maxValue := array[0]
    25  	maxIndex := 0
    26  	for i, v := range array {
    27  		if v > maxValue {
    28  			maxIndex = i
    29  			maxValue = v
    30  		}
    31  	}
    32  	return maxValue, maxIndex
    33  }
    34  
    35  func MaxOfArrayUint(array []uint) (uint, int) {
    36  	maxValue := array[0]
    37  	maxIndex := 0
    38  	for i, v := range array {
    39  		if v > maxValue {
    40  			maxIndex = i
    41  			maxValue = v
    42  		}
    43  	}
    44  	return maxValue, maxIndex
    45  }
    46  
    47  func MinOfArrayUint(array []uint) (uint, int) {
    48  	minValue := array[0]
    49  	minIndex := 0
    50  	for i, v := range array {
    51  		if v < minValue {
    52  			minIndex = i
    53  			minValue = v
    54  		}
    55  	}
    56  	return minValue, minIndex
    57  }
    58  
    59  func SlotsAboveSpecificFreeSlots(slots []uint, threshold uint) []uint {
    60  	var slotsBelow []uint
    61  	for i, v := range slots {
    62  		if v > threshold {
    63  			slotsBelow = append(slotsBelow, uint(i))
    64  		}
    65  	}
    66  	return slotsBelow
    67  }
    68  
    69  func LoadsBelowSpecificLoad(slots []uint, threshold uint) []uint {
    70  	var loadsBelow []uint
    71  	for i, v := range slots {
    72  		if v <= threshold {
    73  			loadsBelow = append(loadsBelow, uint(i))
    74  		}
    75  	}
    76  	return loadsBelow
    77  }
    78  
    79  func ArrayFloatToStringCommas(array []float64) string {
    80  	arrString := ""
    81  
    82  	for i, s := range array {
    83  		arrString += fmt.Sprintf("%f", s)
    84  		if i != len(array)-1 {
    85  			arrString += ","
    86  		}
    87  	}
    88  
    89  	return arrString
    90  }
    91  
View as plain text