Skip to content

Commit ed9721c

Browse files
author
Daniel Dahan
committed
development: progression commit
1 parent 1453ec5 commit ed9721c

16 files changed

+379
-394
lines changed

Sources/Algorithm+Array.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extension Array: Probable {
8282
- Returns: An Int.
8383
*/
8484
public func count<Element: Equatable>(of elements: [Element]) -> Int {
85-
var c: Int = 0
85+
var c = 0
8686
for e in elements {
8787
for x in self {
8888
if e == x as? Element {
@@ -121,7 +121,7 @@ extension Array: Probable {
121121
return 0
122122
}
123123

124-
var c: Int = 0
124+
var c = 0
125125
for e in self {
126126
if block(e) {
127127
c += 1
@@ -137,8 +137,8 @@ extension Array: Probable {
137137
- Parameter elements: A list of Elements.
138138
- Returns: A Double.
139139
*/
140-
public func expectedValue<Element: Equatable>(of trials: Int, for elements: Element...) -> Double {
141-
return expectedValue(of: trials, for: elements)
140+
public func expectedValue<Element: Equatable>(trials: Int, for elements: Element...) -> Double {
141+
return expectedValue(trials: trials, for: elements)
142142
}
143143

144144
/**
@@ -147,7 +147,7 @@ extension Array: Probable {
147147
- Parameter elements: An Array of Elements.
148148
- Returns: A Double.
149149
*/
150-
public func expectedValue<Element: Equatable>(of trials: Int, for elements: [Element]) -> Double {
150+
public func expectedValue<Element: Equatable>(trials: Int, for elements: [Element]) -> Double {
151151
return Double(trials) * probability(of: elements)
152152
}
153153
}

Sources/Algorithm+Set.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension Set: Probable {
4444
- Returns: An Int.
4545
*/
4646
public func count<Element: Equatable>(of elements: [Element]) -> Int {
47-
var c: Int = 0
47+
var c = 0
4848
for e in elements {
4949
for x in self {
5050
if e == x as? Element {
@@ -83,7 +83,7 @@ extension Set: Probable {
8383
return 0
8484
}
8585

86-
var c: Int = 0
86+
var c = 0
8787
for e in self {
8888
if block(e) {
8989
c += 1
@@ -99,8 +99,8 @@ extension Set: Probable {
9999
- Parameter elements: A list of Elements.
100100
- Returns: A Double.
101101
*/
102-
public func expectedValue<Element: Equatable>(of trials: Int, for elements: Element...) -> Double {
103-
return expectedValue(of: trials, for: elements)
102+
public func expectedValue<Element: Equatable>(trials: Int, for elements: Element...) -> Double {
103+
return expectedValue(trials: trials, for: elements)
104104
}
105105

106106
/**
@@ -109,7 +109,7 @@ extension Set: Probable {
109109
- Parameter elements: An Array of Elements.
110110
- Returns: A Double.
111111
*/
112-
public func expectedValue<Element: Equatable>(of trials: Int, for elements: [Element]) -> Double {
112+
public func expectedValue<Element: Equatable>(trials: Int, for elements: [Element]) -> Double {
113113
return Double(trials) * probability(of: elements)
114114
}
115115
}

Sources/Deque.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public struct Deque<Element>: CustomStringConvertible, Sequence {
8282
- returns: String
8383
*/
8484
public var description: String {
85-
return "Deque" + list.internalDescription
85+
return list.description
8686
}
8787

8888
/**

Sources/DoublyLinkedList.swift

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030

3131
public struct DoublyLinkedList<Element>: CustomStringConvertible, Sequence {
32-
public typealias Iterator = AnyIterator<Element>
32+
public typealias Iterator = AnyIterator<Element>
3333

3434
/**
3535
First node in the list.
@@ -55,33 +55,24 @@ public struct DoublyLinkedList<Element>: CustomStringConvertible, Sequence {
5555
*/
5656
public private(set) var count: Int
5757

58-
/**
59-
Returns a String with only the node data for all nodes
60-
in the DoublyLinkedList.
61-
- Returns: A String.
62-
*/
63-
internal var internalDescription: String {
64-
var output: String = "("
65-
var c: Int = 0
66-
var x = head
67-
while nil !== x {
68-
output += "\(x)"
69-
c += 1
70-
if c != count {
71-
output += ", "
72-
}
73-
x = x!.next
74-
}
75-
output += ")"
76-
return output
77-
}
78-
7958
/**
8059
Conforms to Printable Protocol.
8160
- Returns: A String.
8261
*/
8362
public var description: String {
84-
return "DoublyLinkedList" + internalDescription
63+
var output: String = "("
64+
var c = 0
65+
var x = head
66+
while nil !== x {
67+
output += "\(x)"
68+
c += 1
69+
if c != count {
70+
output += ", "
71+
}
72+
x = x!.next
73+
}
74+
output += ")"
75+
return output
8576
}
8677

8778
/**
@@ -109,28 +100,6 @@ public struct DoublyLinkedList<Element>: CustomStringConvertible, Sequence {
109100
return current?.element
110101
}
111102

112-
/**
113-
Retrieves the element at the poistion after the
114-
current cursor poistion. Also moves the cursor
115-
to that node.
116-
- Returns: An optional Element.
117-
*/
118-
public var next: Element? {
119-
current = current?.next
120-
return current?.element
121-
}
122-
123-
/**
124-
Retrieves the element at the poistion before the
125-
current cursor poistion. Also moves the cursor
126-
to that node.
127-
- Returns: An optional Element.
128-
*/
129-
public var previous: Element? {
130-
current = current?.previous
131-
return current?.element
132-
}
133-
134103
/**
135104
A boolean of whether the DoublyLinkedList is empty.
136105
- Returns: A boolean indicating if the DoubleLinkedList is
@@ -165,21 +134,44 @@ public struct DoublyLinkedList<Element>: CustomStringConvertible, Sequence {
165134
count = 0
166135
reset()
167136
}
137+
138+
/**
139+
Retrieves the element at the poistion after the
140+
current cursor poistion. Also moves the cursor
141+
to that node.
142+
- Returns: An optional Element.
143+
*/
144+
@discardableResult
145+
mutating public func next() -> Element? {
146+
current = current?.next
147+
return current?.element
148+
}
149+
150+
/**
151+
Retrieves the element at the poistion before the
152+
current cursor poistion. Also moves the cursor
153+
to that node.
154+
- Returns: An optional Element.
155+
*/
156+
@discardableResult
157+
mutating public func previous() -> Element? {
158+
current = current?.previous
159+
return current?.element
160+
}
168161

169162
/**
170163
Conforms to the SequenceType Protocol. Returns the next value
171164
in the sequence of nodes.
172165
- Returns: A DoublyLinkedList.Iterator.
173166
*/
174167
public func makeIterator() -> DoublyLinkedList.Iterator {
175-
cursorToFront()
176-
return AnyIterator {
177-
if !self.isCursorAtBack {
178-
let element: Element? = self.cursor
179-
_ = self.next
180-
return element
181-
}
182-
return nil
168+
var it = head
169+
return AnyIterator {
170+
guard let e = it?.element else {
171+
return nil
172+
}
173+
it = it?.next
174+
return e
183175
}
184176
}
185177

Sources/Probable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ internal protocol Probable {
5959

6060
/**
6161
The expected value of elements based on a number of trials.
62-
- Parameter of trials: An Int.
62+
- Parameter trials: An Int.
6363
- Parameter for elements: A list of Elements.
6464
- Returns: A Double.
6565
*/
66-
func expectedValue<Element: Equatable>(of trials: Int, for elements: Element...) -> Double
66+
func expectedValue<Element: Equatable>(trials: Int, for elements: Element...) -> Double
6767

6868
/**
6969
The expected value of elements based on a number of trials.
70-
- Parameter of trials: An Int.
70+
- Parameter trials: An Int.
7171
- Parameter for elements: An Array of Elements.
7272
- Returns: A Double.
7373
*/
74-
func expectedValue<Element: Equatable>(of trials: Int, for elements: [Element]) -> Double
74+
func expectedValue<Element: Equatable>(trials: Int, for elements: [Element]) -> Double
7575
}

Sources/Queue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class Queue<Element>: CustomStringConvertible, Sequence {
7272
- returns: String
7373
*/
7474
public var description: String {
75-
return "Queue" + list.internalDescription
75+
return list.description
7676
}
7777

7878
/**

0 commit comments

Comments
 (0)