github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/orbiter/kinds/loadbalancers/dynamic/derived.gen.go (about)

     1  // Code generated by goderive DO NOT EDIT.
     2  
     3  package dynamic
     4  
     5  import (
     6  	infra "github.com/caos/orbos/internal/operator/orbiter/kinds/clusters/core/infra"
     7  )
     8  
     9  // deriveUnique returns a list containing only the unique items from the input list.
    10  // It does this by reusing the input list.
    11  func deriveUnique(list []string) []string {
    12  	if len(list) == 0 {
    13  		return nil
    14  	}
    15  	return deriveKeys(deriveSet(list))
    16  }
    17  
    18  // deriveFilterMachines returns a list of all items in the list that matches the predicate.
    19  func deriveFilterMachines(predicate func(infra.Machine) bool, list []infra.Machine) []infra.Machine {
    20  	j := 0
    21  	for i, elem := range list {
    22  		if predicate(elem) {
    23  			if i != j {
    24  				list[j] = list[i]
    25  			}
    26  			j++
    27  		}
    28  	}
    29  	return list[:j]
    30  }
    31  
    32  // deriveKeys returns the keys of the input map as a slice.
    33  func deriveKeys(m map[string]struct{}) []string {
    34  	keys := make([]string, 0, len(m))
    35  	for key := range m {
    36  		keys = append(keys, key)
    37  	}
    38  	return keys
    39  }
    40  
    41  // deriveSet returns the input list as a map with the items of the list as the keys of the map.
    42  func deriveSet(list []string) map[string]struct{} {
    43  	set := make(map[string]struct{}, len(list))
    44  	for _, v := range list {
    45  		set[v] = struct{}{}
    46  	}
    47  	return set
    48  }