-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/dn-m/Structure
- Loading branch information
Showing
13 changed files
with
1,006 additions
and
70 deletions.
There are no files selected for viewing
512 changes: 512 additions & 0 deletions
512
Sources/DataStructures/ContiguousSegmentCollection/ContiguousSegmentCollection.swift
Large diffs are not rendered by default.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
Sources/DataStructures/ContiguousSegmentCollection/Fragmentable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Fragmentable.swift | ||
// DataStructures | ||
// | ||
// Created by James Bean on 8/22/18. | ||
// | ||
|
||
/// Interface for types which can be fragmented into smaller pieces. | ||
public protocol Fragmentable { | ||
|
||
// MARK: - Associated Types | ||
|
||
/// Type of fragment that is created from this type. | ||
associatedtype Fragment | ||
} |
33 changes: 33 additions & 0 deletions
33
Sources/DataStructures/ContiguousSegmentCollection/Intervallic.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Intervallic.swift | ||
// DataStructures | ||
// | ||
// Created by James Bean on 8/22/18. | ||
// | ||
|
||
import Algebra | ||
|
||
public protocol Intervallic: Measured { | ||
|
||
// MARK - Associated Types | ||
|
||
/// The type which is used to measure this type. | ||
associatedtype Metric | ||
|
||
// MARK: - Instance Properties | ||
|
||
/// Length of the `Spanning` type in the given `Metric`. | ||
var length: Metric { get } | ||
} | ||
|
||
extension Numeric where Self: Comparable { | ||
|
||
/// - Returns: Self as its length. | ||
public var length: Self { | ||
return self | ||
} | ||
} | ||
|
||
extension Int: Intervallic { } | ||
extension Float: Intervallic { } | ||
extension Double: Intervallic { } |
40 changes: 40 additions & 0 deletions
40
Sources/DataStructures/ContiguousSegmentCollection/IntervallicFragmentable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// IntervallicFragmentable.swift | ||
// DataStructures | ||
// | ||
// Created by James Bean on 8/24/18. | ||
// | ||
|
||
import Algebra | ||
|
||
/// Interface for types which are `Intervallic`, and can be fragmented into a type which shares its | ||
/// `Metric` type. | ||
public protocol IntervallicFragmentable: Intervallic, Fragmentable | ||
where Fragment: Intervallic, Fragment.Metric == Metric | ||
{ | ||
|
||
// MARK: - Associated Types | ||
|
||
/// The fragment of an `IntervallicFragmentable` type. | ||
associatedtype Fragment | ||
|
||
// MARK: - Instance Methods | ||
|
||
/// - Returns: The `Fragment` in the given `range`. | ||
func fragment(in range: Range<Metric>) -> Fragment | ||
} | ||
|
||
extension IntervallicFragmentable where Metric: Zero { | ||
|
||
/// - Returns: The `Fragment` of this `IntervallicFragmentable`-conforming type value in the | ||
/// given `range`. | ||
public func fragment(in range: PartialRangeUpTo<Metric>) -> Fragment { | ||
return fragment(in: .zero ..< range.upperBound) | ||
} | ||
|
||
/// - Returns: The `Fragment` of this `IntervallicFragmentable`-conforming type value in the | ||
/// given `range`. | ||
public func fragment(in range: PartialRangeFrom<Metric>) -> Fragment { | ||
return fragment(in: range.lowerBound ..< length) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Sources/DataStructures/ContiguousSegmentCollection/Measured.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Measured.swift | ||
// DataStructures | ||
// | ||
// Created by James Bean on 8/22/18. | ||
// | ||
|
||
/// Interface for types which are measured by some `Metric` type. | ||
public protocol Measured { | ||
|
||
// MARK: - Associated Types | ||
|
||
/// The type which is used to measure this type. | ||
associatedtype Metric: SignedNumeric, Comparable | ||
} |
23 changes: 23 additions & 0 deletions
23
Sources/DataStructures/ContiguousSegmentCollection/Totalizable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Totalizable.swift | ||
// DataStructures | ||
// | ||
// Created by James Bean on 8/22/18. | ||
// | ||
|
||
import Algebra | ||
|
||
/// Interface for fragment types which can create a fragment version of a whole instance of the | ||
/// type. | ||
public protocol Totalizable { | ||
|
||
// MARK: - Associated Types | ||
|
||
/// The type of the given `Whole`. | ||
associatedtype Whole | ||
|
||
// MARK: - Initializers | ||
|
||
/// Creates a `Totalizable` fragment with an instance of the `Whole` type. | ||
init(whole: Whole) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.