各种集合与数据结构 (Various Collections and Data Structures)
import Generator
import Graph
import Pair
dependencies: [
.package(url: "https://github.com/DavidSkrundz/Collections.git",
from: "2.0.0")
],
targets: [
.target(
name: "",
dependencies: [
"Generator", "Graph", "Pair"
]),
]
实现了 Iterator
协议,但也允许反向迭代 (previous() -> Element?
)
一个实现了基本功能的图类 (A basic graph class that implements)
func neighbours(of vertex: Vertex<T>) -> [Vertex<T>]
func reachable(from vertex: Vertex<T>) -> [Vertex<T>]
reachable(from vertex: Vertex<T>, where canReach: (_ distance: Int, _ edge: U?) -> Bool) -> [Vertex<T>]
类似于 zip(_:_:)
,但返回一个包含两个序列的笛卡尔积(所有配对)的 Sequence
(Like zip(_:_:)
but returns a Sequence
containing the cartesian product (all pairs) of the two sequences)