การสุ่มตัวอย่าง

public struct Sampling<Base: Collection, Selection: Collection>
where Selection.Element == Base.Index
extension Sampling: SamplingProtocol
extension Sampling: Collection
extension Sampling: BidirectionalCollection
  where Selection: BidirectionalCollection
extension Sampling: RandomAccessCollection
  where Selection: RandomAccessCollection

การเลือกองค์ประกอบอย่างเกียจคร้าน ตามลำดับที่กำหนด จากคอลเลกชันฐานบางส่วน

  • สร้างอินสแตนซ์จาก base และ selection

    คำประกาศ

    public init(base: Base, selection: Selection)
  • คำประกาศ

    public typealias Element = Base.Element
  • ประเภทที่อินสแตนซ์แสดงถึงตำแหน่งใน self

    คำประกาศ

    public typealias Index = Selection.Index
  • ตำแหน่งขององค์ประกอบแรก

    คำประกาศ

    public var startIndex: Index { get }
  • ตำแหน่งที่หนึ่งผ่านองค์ประกอบสุดท้าย

    คำประกาศ

    public var endIndex: Index { get }
  • ส่งคืนองค์ประกอบที่ i

    คำประกาศ

    public subscript(i: Index) -> Element { get }
  • ส่งกลับตำแหน่งหลังจาก i

    คำประกาศ

    public func index(after i: Index) -> Index
  • ส่งกลับจำนวนขั้นตอนการส่งต่อที่จำเป็นในการแปลง start เป็น end

    ผลลัพธ์ที่เป็นลบบ่งชี้ว่า end < start

    คำประกาศ

    public func distance(from start: Index, to end: Index) -> Int
  • ส่งกลับตำแหน่ง n ตำแหน่งจาก i

    คำประกาศ

    public func index(_ i: Index, offsetBy n: Int) -> Index
  • คืนค่า i ชดเชยด้วย distance เว้นแต่ว่าต้องผ่าน limit ซึ่งในกรณีนี้จะส่งคืน nil

    คำประกาศ

    public func index(
      _ i: Index, offsetBy distance: Int, limitedBy limit: Index
    ) -> Index?
มีจำหน่ายที่ `Selection`: `BiDirectionalCollection`