SwiftAlgorithms是Swift标准库团队开源的一系列关于序列(sequece)和集合 (collectio)类型及相关类型的算法包。
SwiftAlgorithms包含各种与序列和集合有关的运算,例如循环集合元素处理、排列组合,以及随机采样等功能。
combiatios(ofCout:): 集合中特定大小元素的组合permutatios(ofCout:):集合或完整集合中特定大小元素的排列radomSample(cout:), radomSample(cout:usig:):从一个集合中随机收集特定数量的元素radomStableSample(cout:), radomStableSample(cout:usig:):从一个集合中随机收集特定数量的元素,并保留其原始相对顺序idexed():遍历集合索引和元素的元组使用
添加SwiftAlgorithms作为依赖
在Package.swift文件中添加以下命令行到依赖中:
.package(url:"https://github.com/apple/swift-algorithms",from:"0.0.1"),然后将"Algorithms"作为可执行target的依赖项:
letpackage=Package(//ame,platforms,products,etc.depedecies:[.package(url:"https://github.com/apple/swift-algorithms",from:"0.0.1"),//otherdepedecies],targets:[.target(ame:"<target>",depedecies:[.product(ame:"Algorithms",package:"swift-algorithms"),]),//othertargets])









评论