Skip to content

Commit

Permalink
Update to Swift 4.2's Hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Jan 29, 2019
1 parent ca77cd6 commit ac16054
Show file tree
Hide file tree
Showing 28 changed files with 528 additions and 360 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
4.2.1
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ notifications:
email: false
matrix:
include:
- os: osx
osx_image: xcode10
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- swift build
- swift test

- os: osx
osx_image: xcode9
env:
- SWIFT_VERSION=4.0
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
Expand All @@ -30,6 +40,15 @@ matrix:
- swift build
- swift test

- os: linux
env:
- SWIFT_VERSION=4.0
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- swift build
- swift test

- os: linux
env:
- SWIFT_VERSION=3.0
Expand Down
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 3.1.0
## 3.1.1

### Fixes

*Not released yet*
- Avoid assertion failure by combining hash values instead of summing them up - @iLuke93 @snofla

## 3.1.0

### Additions

Expand Down
2 changes: 1 addition & 1 deletion Finite.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Finite'
s.version = '3.1.0'
s.version = '3.1.1'
s.summary = 'A simple state machine written in Swift.'
s.description = <<-DESC
Finite is a simple, pure Swift finite state machine.
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

gem "cocoapods", "~> 1.5"
gem "jazzy", "~> 0.9.4"
102 changes: 102 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
GEM
specs:
CFPropertyList (3.0.0)
activesupport (4.2.10)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
atomos (0.1.3)
claide (1.0.2)
cocoapods (1.5.3)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.5.3)
cocoapods-deintegrate (>= 1.0.2, < 2.0)
cocoapods-downloader (>= 1.2.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.3.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (~> 2.0.1)
gh_inspector (~> 1.0)
molinillo (~> 0.6.5)
nap (~> 1.0)
ruby-macho (~> 1.1)
xcodeproj (>= 1.5.7, < 2.0)
cocoapods-core (1.5.3)
activesupport (>= 4.0.2, < 6)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.2.2)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.3.1)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.1.0)
colored2 (3.1.2)
concurrent-ruby (1.1.3)
escape (0.0.4)
ffi (1.9.25)
fourflusher (2.0.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jazzy (0.9.4)
cocoapods (~> 1.0)
mustache (~> 0.99)
open4
redcarpet (~> 3.2)
rouge (>= 2.0.6, < 4.0)
sass (~> 3.4)
sqlite3 (~> 1.3)
xcinvoke (~> 0.3.0)
liferaft (0.0.6)
minitest (5.11.3)
molinillo (0.6.6)
mustache (0.99.8)
nanaimo (0.2.6)
nap (1.1.0)
netrc (0.11.0)
open4 (1.3.4)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
redcarpet (3.4.0)
rouge (3.3.0)
ruby-macho (1.3.1)
sass (3.7.2)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sqlite3 (1.3.13)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
xcinvoke (0.3.0)
liferaft (~> 0.0.6)
xcodeproj (1.7.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.6)

PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 1.5)
jazzy (~> 0.9.4)

BUNDLED WITH
1.16.2
76 changes: 39 additions & 37 deletions Sources/Transition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,73 @@
//

/**
The Transition class represents a transition from a given state to a targeted state.
There are three types of transitions:
The Transition class represents a transition from a given state to a targeted state.
There are three types of transitions:
1. Absolute Transitions have a source and a target state set.
2. Relative Transitions have only one state set.
3. Nil Transitions have none states set and will be ignored.
*/
1. Absolute Transitions have a source and a target state set.
2. Relative Transitions have only one state set.
3. Nil Transitions have none states set and will be ignored.
*/
public struct Transition<T: Hashable>: Hashable, CustomStringConvertible {

/// Nil transitions will be ignored.
public static var nilTransition: Transition<T> {
return Transition<T>(from: nil, to: nil)
}

/// The source state.
public var from: T?
/// The targeted state.
public var to: T?

/**
Constructs an absolute, relative or nil transition.
- parameter from: The source state.
- parameter to: The target state.
*/
Constructs an absolute, relative or nil transition.
- parameter from: The source state.
- parameter to: The target state.
*/
public init(from: T?, to: T?) {
self.from = from
self.to = to
}

/**
All more general transitions include itself except the nil transition.
- returns: All general transitions.
- Generals of an absolute transition is itself and relative transitions.
- Generals of a relative transition is only itself.
- Nil transitions have no generals.
*/
/**
All more general transitions include itself except the nil transition.
- returns: All general transitions.
- Generals of an absolute transition is itself and relative transitions.
- Generals of a relative transition is only itself.
- Nil transitions have no generals.
*/
public var generalTransitions: Set<Transition> {
var generals = Set<Transition>([self, Transition(from: from, to: nil), Transition(from: nil, to: to)])
generals.remove(.nilTransition)
return generals
}

// Synthesized by compiler
public func hash(into hasher: inout Hasher) {
hasher.combine(self.from)
hasher.combine(self.to)
}

public var hashValue: Int {
var hasher = Hasher()
self.hash(into: &hasher)
return hasher.finalize()
}


public var description: String {
let f = from != nil ? String(describing: from!) : "any"
let t = to != nil ? String(describing: to!) : "any"
return "\(f) -> \(t)"
}

#if swift(>=4.2)
// Synthesized by compiler
/// :nodoc:
public func hash(into hasher: inout Hasher) {
hasher.combine(from)
hasher.combine(to)
}

#else
/// :nodoc:
public var hashValue: Int {
return (from?.hashValue ?? 0) + (to?.hashValue ?? 0)
}
#endif
}

/// :nodoc:
public func ==<T>(lhs: Transition<T>, rhs: Transition<T>) -> Bool {
public func == <T>(lhs: Transition<T>, rhs: Transition<T>) -> Bool {
return lhs.from == rhs.from && lhs.to == rhs.to
}
9 changes: 5 additions & 4 deletions docs/Enums.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</head>
<body>

<a name="//apple_ref/swift/Section/Enumerations" class="dashAnchor"></a>

<a title="Enumerations Reference"></a>

Expand All @@ -22,7 +23,7 @@
<a class="header-link" href="index.html">
Finite Docs
</a>
(100% documented)
(97% documented)
</p>

<p class="header-col--secondary">
Expand Down Expand Up @@ -114,7 +115,7 @@ <h1>Enumerations</h1>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">enum</span> <span class="kt">TransitionError</span><span class="o">&lt;</span><span class="kt">T</span><span class="p">:</span> <span class="kt">Hashable</span><span class="o">&gt;</span><span class="p">:</span> <span class="kt">Error</span></code></pre>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">enum</span> <span class="kt">TransitionError</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span> <span class="p">:</span> <span class="kt">Error</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt">Hashable</span></code></pre>

</div>
</div>
Expand All @@ -129,8 +130,8 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2017 <a class="link" href="https://twitter.com/vknabel" target="_blank" rel="external">Valentin Knabel</a>. All rights reserved. (Last updated: 2017-11-06)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.0</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
<p>&copy; 2019 <a class="link" href="https://twitter.com/vknabel" target="_blank" rel="external">Valentin Knabel</a>. All rights reserved. (Last updated: 2019-01-29)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
</div>
Expand Down
16 changes: 8 additions & 8 deletions docs/Enums/TransitionError.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<a class="header-link" href="../index.html">
Finite Docs
</a>
(100% documented)
(97% documented)
</p>

<p class="header-col--secondary">
Expand Down Expand Up @@ -87,7 +87,7 @@
<h1>TransitionError</h1>
<div class="declaration">
<div class="language">
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">enum</span> <span class="kt">TransitionError</span><span class="o">&lt;</span><span class="kt">T</span><span class="p">:</span> <span class="kt">Hashable</span><span class="o">&gt;</span><span class="p">:</span> <span class="kt">Error</span></code></pre>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">enum</span> <span class="kt">TransitionError</span><span class="o">&lt;</span><span class="kt">T</span><span class="o">&gt;</span> <span class="p">:</span> <span class="kt">Error</span> <span class="k">where</span> <span class="kt">T</span> <span class="p">:</span> <span class="kt">Hashable</span></code></pre>

</div>
</div>
Expand All @@ -103,9 +103,9 @@ <h1>TransitionError</h1>
<li class="item">
<div>
<code>
<a name="/s:6Finite15TransitionErrorO6deniedACyxGx4from_x2totcAEms8HashableRzlF"></a>
<a name="//apple_ref/swift/Element/denied" class="dashAnchor"></a>
<a class="token" href="#/s:6Finite15TransitionErrorO6deniedACyxGx4from_x2totcAEms8HashableRzlF">denied</a>
<a name="/s:6Finite15TransitionErrorO6deniedyACyxGx_xtcAEmSHRzlF"></a>
<a name="//apple_ref/swift/Element/denied(from:to:)" class="dashAnchor"></a>
<a class="token" href="#/s:6Finite15TransitionErrorO6deniedyACyxGx_xtcAEmSHRzlF">denied(from:to:)</a>
</code>
</div>
<div class="height-container">
Expand All @@ -120,7 +120,7 @@ <h1>TransitionError</h1>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="k">case</span> <span class="nf">denied</span><span class="p">(</span><span class="nv">from</span><span class="p">:</span> <span class="kt">T</span><span class="p">,</span> <span class="nv">to</span><span class="p">:</span> <span class="kt">T</span><span class="p">)</span></code></pre>
<pre class="highlight swift"><code><span class="k">case</span> <span class="nf">denied</span><span class="p">(</span><span class="nv">from</span><span class="p">:</span> <span class="kt">T</span><span class="p">,</span> <span class="nv">to</span><span class="p">:</span> <span class="kt">T</span><span class="p">)</span></code></pre>

</div>
</div>
Expand All @@ -135,8 +135,8 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2017 <a class="link" href="https://twitter.com/vknabel" target="_blank" rel="external">Valentin Knabel</a>. All rights reserved. (Last updated: 2017-11-06)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.0</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
<p>&copy; 2019 <a class="link" href="https://twitter.com/vknabel" target="_blank" rel="external">Valentin Knabel</a>. All rights reserved. (Last updated: 2019-01-29)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
</div>
Expand Down
Loading

0 comments on commit ac16054

Please sign in to comment.