Provide additional methods under the CPUSet

- ToSliceInt64 returns sorted slice of cores IDs in int64 format
- ToSliceNoSortInt64 returns slice of cores IDs in int64 format

Signed-off-by: Artyom Lukianov <alukiano@redhat.com>
This commit is contained in:
Artyom Lukianov 2021-01-18 19:59:23 +02:00
parent 3b38f6a08e
commit 69db36b958

View File

@ -19,11 +19,12 @@ package cpuset
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"k8s.io/klog/v2"
"reflect" "reflect"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"k8s.io/klog/v2"
) )
// Builder is a mutable builder for CPUSet. Functions that mutate instances // Builder is a mutable builder for CPUSet. Functions that mutate instances
@ -198,6 +199,27 @@ func (s CPUSet) ToSliceNoSort() []int {
return result return result
} }
// ToSliceInt64 returns an ordered slice of int64 that contains all elements from
// this set
func (s CPUSet) ToSliceInt64() []int64 {
var result []int64
for cpu := range s.elems {
result = append(result, int64(cpu))
}
sort.Slice(result, func(i, j int) bool { return result[i] < result[j] })
return result
}
// ToSliceNoSortInt64 returns a slice of int64 that contains all elements from
// this set.
func (s CPUSet) ToSliceNoSortInt64() []int64 {
var result []int64
for cpu := range s.elems {
result = append(result, int64(cpu))
}
return result
}
// String returns a new string representation of the elements in this CPU set // String returns a new string representation of the elements in this CPU set
// in canonical linux CPU list format. // in canonical linux CPU list format.
// //