ContiguousSegmentCollection
public struct ContiguousSegmentCollection <Segment: Intervallic>
where Segment.Metric: Hashable & Additive
extension ContiguousSegmentCollection: Intervallic
extension ContiguousSegmentCollection: RandomAccessCollectionWrapping
extension ContiguousSegmentCollection: ExpressibleByArrayLiteral
extension ContiguousSegmentCollection: CustomStringConvertible
extension ContiguousSegmentCollection: Fragmentable where
Metric: Zero,
Segment: IntervallicFragmentable,
Segment.Fragment: IntervallicFragmentable,
Segment.Fragment.Fragment == Segment.Fragment
extension ContiguousSegmentCollection: Equatable where Segment: Equatable
extension ContiguousSegmentCollection: Hashable where Segment: Hashable
A generic collection of contiguous Intervallic
-type value wherein Intervallic
types are
stored by their offset.
Example Usage
let collection: ContiguousSegmentCollection = [1,2,1,3]
This creates a ContiguousSegmentCollection<Int>
, where the Metric
and Intervallic
types
are both Int
. Each segment is the length of a given value, and is stored by the accumulating
offset.
The resulting structure could be represented like this:
offset: 0 1 3 4 7
|-|--|-|---|
length: 1 2 1 3
-
The type which is used to measure the
Segment
.Declaration
Swift
public typealias Metric = Segment.Metric
-
ContiguousSegmentCollection
with no segments.Declaration
Swift
public static var empty: ContiguousSegmentCollection { get }
-
Creates a
ContiguousSegmentCollection
with the givenpresorted
SortedDictionary
of values.Declaration
Swift
public init(_ presorted: SortedDictionary<Metric, Segment>)
-
Creates a
ContiguousSegmentCollection
with the givensequence
of segments.Declaration
Swift
public init<S>(_ sequence: S, offset: Metric = .zero) where Segment == S.Element, S : Sequence
-
Creates a
ContiguousSegmentCollection
with the givencollection
of segments.Declaration
Swift
public init <C: Collection> (_ collection: C, offset: Metric = .zero) where C.Element == Segment
-
Creates a
ContiguousSegmentCollection
with the givenpresorted
collection of key-value pairs.Declaration
Swift
public init<C>(presorted: C) where C : Collection, C.Element == (Segment.Metric, Segment)
-
Declaration
Swift
public var offsets: AnyCollection<Metric> { get }
Return Value
A collection of the offsets of each spanner contained herein.
-
Declaration
Swift
public var segments: AnyCollection<Segment> { get }
Return Value
A collection of the spanners contained herein.
-
Declaration
Swift
public var normalized: ContiguousSegmentCollection { get }
Return Value
A
ContiguousSegmentCollection
with alloffsets
reduced such that the first offset is0
.
-
Declaration
Swift
public var base: SortedDictionary<Metric, Segment> { get }
Return Value
A view of the underlying storage producing a
RandomAccessCollection
interface.
-
A fragment of a
See moreContiguousSegmentCollection
.Declaration
Swift
public struct Fragment
extension ContiguousSegmentCollection.Fragment: RandomAccessCollectionWrapping
extension ContiguousSegmentCollection.Fragment: IntervallicFragmentable
extension ContiguousSegmentCollection.Fragment: Equatable where Segment: Equatable, Segment.Fragment: Equatable
-
Declaration
Swift
public func indexOfSegment(containing offset: Metric) -> Int?
Return Value
The index of the segment containing the given
offset
, if it exists. Otherwise,nil
.
-
Creates a
ContiguousSegmentCollection
with the given array literal.Declaration
Swift
public init(arrayLiteral elements: Segment...)
-
Declaration
Swift
public var description: String { get }