接口
interface SortByExtension
public interface SortByExtension
功能: 此接口作为排序相关的辅助接口,内部为空。
extend<T> Array<T> <: SortByExtension
extend<T> Array<T> <: SortByExtension
功能: 此扩展用于实现 Array 的 sortBy
函数。
父类型:
func sortBy(Bool, (T, T) -> Ordering)
public func sortBy(stable!: Bool = false, comparator!: (T, T) -> Ordering): Unit
功能:通过传入的比较函数,根据其返回值 Ordering 类型的结果,可对数组进行自定义排序。
参数:
- stable!: Bool - 是否使用稳定排序。
- comparator!: (T, T) ->Ordering - 用户传入的比较函数,如,comparator: (t1: T, t2: T) -> Ordering,如果
comparator
的返回值为 Ordering.GT,排序后t1
在t2
后;如果comparator
的返回值为 Ordering.LT,排序后t1
在t2
前;如果comparator
的返回值为 Ordering.EQ,且为稳定排序那么t1
与t2
的位置较排序前保持不变; 如果comparator
的返回值为 Ordering.EQ,且为不稳定排序,那么t1
,t2
顺序不确定
interface SortExtension
public interface SortExtension
功能: 此接口作为排序相关的辅助接口,内部为空。
extend<T> Array<T> <: SortExtension where T <: Comparable<T>
extend<T> Array<T> <: SortExtension where T <: Comparable<T>
功能: 此扩展用于实现 Array 的 sort/sortDescending
函数。
父类型:
func sort(Bool)
public func sort(stable!: Bool = false): Unit
功能:以升序的方式排序 Array。
参数:
- stable!: Bool - 是否使用稳定排序。
func sortDescending(Bool)
public func sortDescending(stable!: Bool = false): Unit
功能:以降序的方式排序 Array。
参数:
- stable!: Bool - 是否使用稳定排序。