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)
| 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. |
| 43 | func (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. |
no outgoing calls