MCPcopy
hub / github.com/minio/minio-go / ToSlice

Method ToSlice

pkg/set/set.go:43–52  ·  view source on GitHub ↗

ToSlice - returns Set as a slice sorted using the provided comparison function. If cmpFn is nil, the slice order is undefined (non-deterministic). Important: The comparison function should provide total ordering. If it returns 0 for elements that are not identical, their relative order in the resul

(cmpFn func(a, b T) int)

Source from the content-addressed store, hash-verified

41// for elements that are not identical, their relative order in the result is undefined.
42// For deterministic results, use secondary sort criteria for tie-breaking.
43func (set Set[T]) ToSlice(cmpFn func(a, b T) int) []T {
44 keys := make([]T, 0, len(set))
45 for k := range set {
46 keys = append(keys, k)
47 }
48 if cmpFn != nil {
49 slices.SortFunc(keys, cmpFn)
50 }
51 return keys
52}
53
54// ToSliceOrdered - returns Set as a sorted slice for ordered types.
55// This is a convenience method for types that implement cmp.Ordered.

Callers 15

TestIntSetToSliceFunction · 0.45
TestIntSet_UnmarshalJSONFunction · 0.45
TestStringSetMsgpBinaryFunction · 0.45
TestIntSetMsgpRoundtripFunction · 0.45
TestIntSetMsgpBinaryFunction · 0.45
TestMsgpSortedBehaviorFunction · 0.45

Calls

no outgoing calls

Tested by 15

TestIntSetToSliceFunction · 0.36
TestIntSet_UnmarshalJSONFunction · 0.36
TestStringSetMsgpBinaryFunction · 0.36
TestIntSetMsgpRoundtripFunction · 0.36
TestIntSetMsgpBinaryFunction · 0.36
TestMsgpSortedBehaviorFunction · 0.36