Skip to content

Commit

Permalink
Add Codable Conformance to Pair types, replace deprecated usage (#211)
Browse files Browse the repository at this point in the history
* Add Codable conformance to Pair types

* Update dependencies

* Replace deprecated index usage

* Replace deprecated hashValue usage
  • Loading branch information
bwetherfield authored Jun 30, 2019
1 parent 011e5ff commit b659f8a
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"package": "PerformanceTesting",
"repositoryURL": "https://github.com/dn-m/PerformanceTesting",
"state": {
"branch": null,
"revision": "d48417c837b1a029dd9567dfa7b5ee3cfa9a0ec7",
"version": "0.3.0"
"branch": "pitchspeller-dependency",
"revision": "fd97209b9465e698c51cb30dfc24db35f39fa5c5",
"version": null
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.2
// swift-tools-version:5.0

import PackageDescription

Expand All @@ -11,7 +11,7 @@ let package = Package(
.library(name: "Algorithms", targets: ["Algorithms"])
],
dependencies: [
.package(url: "https://github.com/dn-m/PerformanceTesting", from: "0.2.0")
.package(url: "https://github.com/dn-m/PerformanceTesting", .branch("pitchspeller-dependency"))
],
targets: [

Expand Down
2 changes: 1 addition & 1 deletion Sources/DataStructures/InvertibleEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public protocol InvertibleEnum: CaseIterable, Equatable {
extension InvertibleEnum where AllCases.Index == Int {
/// - Returns: Inverse of `self`.
public var inverse: Self {
let index = Self.allCases.index(of: self)!
let index = Self.allCases.firstIndex(of: self)!
let inverseIndex = Self.allCases.count - (1 + index)
return Self.allCases[inverseIndex]
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataStructures/Metatype.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ extension Metatype: Hashable {
/// - Returns: A unique hash value for the metatype wrapped-up herein.
@inlinable
public func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(base).hashValue)
hasher.combine(ObjectIdentifier(base))
}
}
5 changes: 3 additions & 2 deletions Sources/DataStructures/NewType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ extension NewType where Value: Equatable {
}

extension NewType where Value: Hashable {
public var hashValue: Int {
return value.hashValue

public func hash(into hasher: inout Hasher) {
hasher.combine(value)
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/DataStructures/Pair/Cross.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extension Cross: Comparable where T: Comparable, U: Comparable {

extension Cross: Equatable where T: Equatable, U: Equatable { }
extension Cross: Hashable where T: Hashable, U: Hashable { }
extension Cross: Codable where T: Codable, U: Codable { }

extension Cross: CustomStringConvertible {

Expand Down
1 change: 1 addition & 0 deletions Sources/DataStructures/Pair/OrderedPair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public struct OrderedPair <T>: SwappablePair {

extension OrderedPair: Equatable where T: Equatable { }
extension OrderedPair: Hashable where T: Hashable { }
extension OrderedPair: Codable where T: Codable { }

extension OrderedPair: CustomStringConvertible {

Expand Down
2 changes: 2 additions & 0 deletions Sources/DataStructures/Pair/UnorderedPair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ extension UnorderedPair: Hashable where T: Hashable {
}
}

extension UnorderedPair: Codable where T: Codable { }

extension UnorderedPair: CustomStringConvertible {

// MARK: - CustomStringConvertible
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataStructures/ReferenceTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class ReferenceTree {
*/
public func removeChild(_ node: ReferenceTree) throws {

guard let index = children.index(where: { $0 === node }) else {
guard let index = children.firstIndex(where: { $0 === node }) else {
throw Error.nodeNotFound
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/DataStructures/ReferenceTreeProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public extension ReferenceTreeProtocol {
/// - throws: `ReferenceTreeError.removalError` if the given `node` is not held in `children`.
func removeChild(_ node: Self) throws {

guard let index = children.index(where: { $0 === node }) else {
guard let index = children.firstIndex(where: { $0 === node }) else {
throw ReferenceTreeError.nodeNotFound
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/DataStructures/SortedArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct SortedArray <Element: Comparable>:
///
/// - TODO: Make `throws` instead of returning silently.
public mutating func remove(_ element: Element) {
guard let index = base.index(of: element) else { return }
guard let index = base.firstIndex(of: element) else { return }
base.remove(at: index)
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/DataStructures/Wrapping/DoubleWrapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ extension DoubleWrapping {

// MARK: - Hashable

public var hashValue: Int { return value.hashValue }
public func hash(into hasher: inout Hasher) {
hasher.combine(value)
}
}

// MARK: - Comparable
Expand Down
4 changes: 3 additions & 1 deletion Sources/DataStructures/Wrapping/FloatWrapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ extension FloatWrapping {

// MARK: - Hashable

public var hashValue: Int { return value.hashValue }
public func hash(into hasher: inout Hasher) {
hasher.combine(value)
}
}

// MARK: - Comparable
Expand Down
4 changes: 2 additions & 2 deletions Sources/DataStructures/Wrapping/IntegerWrapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ extension IntegerWrapping {

// MARK: - Hashable

public var hashValue: Int {
return value.hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(value)
}
}

Expand Down

0 comments on commit b659f8a

Please sign in to comment.