Skip to content

Commit

Permalink
Merge pull request #126 from dn-m/clean-up-dict-proto
Browse files Browse the repository at this point in the history
[QoI] Refine implementation of DataStructures
  • Loading branch information
jsbean authored Jul 28, 2018
2 parents 46e8b74 + cd25bbe commit 3a2c3d1
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 440 deletions.
10 changes: 10 additions & 0 deletions Sources/Algebra/Group.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Group.swift
// Algebra
//
// Created by James Bean on 7/26/18.
//

/// Interface defining objects which operate as a group. `Group` extends the requirements of
/// `Monoid` by adding the `Invertible` requirement.
public protocol Group: Monoid, Invertible { }
11 changes: 11 additions & 0 deletions Sources/Algebra/Invertible.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Invertible.swift
// Algebra
//
// Created by James Bean on 7/26/18.
//

/// Interface for types which have an inverse.
public protocol Invertible {
var inverse: Self { get }
}
25 changes: 8 additions & 17 deletions Sources/DataStructures/CircularArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
//
//

import Algebra

/// Array-like structure that allows retrieval of elements at indices outside of the bounds of
/// the internal storage.
public struct CircularArray<Element> {

internal var storage: Array<Element>
private var storage: Array<Element>

// MARK: - Initializers

Expand Down Expand Up @@ -68,6 +66,12 @@ public struct CircularArray<Element> {
}
}

extension CircularArray: RandomAccessCollectionWrapping {
public var base: [Element] {
return storage
}
}

extension CircularArray: BidirectionalCollection {

/// Start index.
Expand Down Expand Up @@ -98,14 +102,6 @@ extension CircularArray: BidirectionalCollection {
}
}

extension CircularArray: RandomAccessCollection {

/// - Returns: A reversed copy of `CircularArray`.
public func reversed() -> CircularArray {
return CircularArray(storage.reversed())
}
}

extension CircularArray: RangeReplaceableCollection {

/// Replaces the specified subrange of elements with the given collection.
Expand Down Expand Up @@ -157,12 +153,7 @@ extension CircularArray: RangeReplaceableCollection {
}

extension CircularArray: Equatable where Element: Equatable {

/// - Returns: `true` if the elements contained both `CircularArray` values are equivalent.
/// Otherwise, `false`.
public static func == (lhs: CircularArray, rhs: CircularArray) -> Bool {
return lhs.storage == rhs.storage
}
// MARK: - Equatable
}

extension CircularArray: ExpressibleByArrayLiteral {
Expand Down
Loading

0 comments on commit 3a2c3d1

Please sign in to comment.