...

Source file src/scheduler/utils/arrays.go

Documentation: scheduler/utils

     1  /*
     2   * P2PFaaS - A framework for FaaS Load Balancing
     3   * Copyright (c) 2019 - 2022. Gabriele Proietti Mattia <pm.gabriele@outlook.com>
     4   *
     5   * This program is free software: you can redistribute it and/or modify
     6   * it under the terms of the GNU General Public License as published by
     7   * the Free Software Foundation, either version 3 of the License, or
     8   * (at your option) any later version.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
    17   */
    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