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

Type Aliases

  • The type which is used to measure the Segment.

    Declaration

    Swift

    public typealias Metric = Segment.Metric

Type Properties

  • ContiguousSegmentCollection with no segments.

    Declaration

    Swift

    public static var empty: ContiguousSegmentCollection { get }

Initializers

  • Creates a ContiguousSegmentCollection with the given presorted SortedDictionary of values.

    Declaration

    Swift

    public init(_ presorted: SortedDictionary<Metric, Segment>)
  • Creates a ContiguousSegmentCollection with the given sequence of segments.

    Declaration

    Swift

    public init<S>(_ sequence: S, offset: Metric = .zero) where Segment == S.Element, S : Sequence
  • Creates a ContiguousSegmentCollection with the given collection of segments.

    Declaration

    Swift

    public init <C: Collection> (_ collection: C, offset: Metric = .zero)
        where C.Element == Segment
  • Creates a ContiguousSegmentCollection with the given presorted collection of key-value pairs.

    Declaration

    Swift

    public init<C>(presorted: C) where C : Collection, C.Element == (Segment.Metric, Segment)

Computed Properties

  • 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 all offsets reduced such that the first offset is 0.

  • Declaration

    Swift

    public func offsetBy(_ amount: Metric) -> ContiguousSegmentCollection

    Return Value

    A ContiguousSegmentCollection with the offsets offset by the given amount.

Intervallic

  • Declaration

    Swift

    public var length: Metric { get }

    Return Value

    The length of ContiguousSegmentCollection.

  • Declaration

    Swift

    public func contains(_ target: Metric) -> Bool

    Return Value

    true if the target is within the bounds of this ContiguousSegmentCollection.

RandomAccessCollectionWrapping

  • Declaration

    Swift

    public var base: SortedDictionary<Metric, Segment> { get }

    Return Value

    A view of the underlying storage producing a RandomAccessCollection interface.

Nested Types

ExpressibleByArrayLiteral

  • Creates a ContiguousSegmentCollection with the given array literal.

    Declaration

    Swift

    public init(arrayLiteral elements: Segment...)

CustomStringConvertible

  • Declaration

    Swift

    public var description: String { get }