Skip to content

Commit 11f4c1f

Browse files
author
Daniel Dahan
committed
removed c-style looping and operations
1 parent d22803d commit 11f4c1f

12 files changed

+144
-111
lines changed

Algorithm.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Algorithm'
3-
s.version = '1.0.6'
3+
s.version = '1.0.7'
44
s.license = 'BSD'
55
s.summary = 'A toolset for writing algorithms in Swift.'
66
s.homepage = 'http://cosmicmind.io'

Sources/Algorithm+Array.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extension Array : ProbableType {
6363
for v in elements {
6464
for x in self {
6565
if v == x as! Element {
66-
++c
66+
c += 1
6767
}
6868
}
6969
}
@@ -95,7 +95,7 @@ extension Array : ProbableType {
9595
var c: Int = 0
9696
for x in self {
9797
if block(element: x) {
98-
++c
98+
c += 1
9999
}
100100
}
101101
return Double(c) / Double(count)

Sources/Algorithm+Set.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension Set : ProbableType {
4444
for v in elements {
4545
for x in self {
4646
if v == x as! Element {
47-
++c
47+
c += 1
4848
}
4949
}
5050
}
@@ -76,7 +76,7 @@ extension Set : ProbableType {
7676
var c: Int = 0
7777
for x in self {
7878
if block(element: x) {
79-
++c
79+
c += 1
8080
}
8181
}
8282
return Double(c) / Double(count)

Sources/DoublyLinkedList.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
7171
var x: DoublyLinkedListNode<Element>? = head
7272
while nil !== x {
7373
output += "\(x)"
74-
if ++c != count {
74+
c += 1
75+
if c != count {
7576
output += ", "
7677
}
7778
x = x!.next
@@ -187,7 +188,7 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
187188
//
188189
public func generate() -> DoublyLinkedList.Generator {
189190
cursorToFront()
190-
return anyGenerator {
191+
return AnyGenerator {
191192
if !self.isCursorAtBack {
192193
let element: Element? = self.cursor
193194
self.next
@@ -222,7 +223,8 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
222223
head!.previous = z
223224
}
224225
head = z
225-
if 1 == ++count {
226+
count += 1
227+
if 1 == count {
226228
current = head
227229
} else if head === current {
228230
current = head!.next
@@ -240,7 +242,8 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
240242
return nil
241243
}
242244
let element: Element? = head!.element
243-
if 0 == --count {
245+
count -= 1
246+
if 0 == count {
244247
reset()
245248
} else {
246249
head = head!.next
@@ -263,7 +266,8 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
263266
tail!.next = z
264267
}
265268
tail = z
266-
if 1 == ++count {
269+
count += 1
270+
if 1 == count {
267271
current = tail
268272
} else if tail === current {
269273
current = tail!.previous
@@ -281,7 +285,8 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
281285
return nil
282286
}
283287
let element: Element? = tail!.element
284-
if 0 == --count {
288+
count -= 1
289+
if 0 == count {
285290
reset()
286291
} else {
287292
tail = tail!.previous
@@ -316,7 +321,7 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
316321
let z: DoublyLinkedListNode<Element> = DoublyLinkedListNode<Element>(next: current, previous: current!.previous, element: element)
317322
current!.previous?.next = z
318323
current!.previous = z
319-
++count
324+
count += 1
320325
}
321326
}
322327

@@ -331,7 +336,7 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
331336
let z: DoublyLinkedListNode<Element> = DoublyLinkedListNode<Element>(next: current!.next, previous: current, element: element)
332337
current!.next?.previous = z
333338
current!.next = z
334-
++count
339+
count += 1
335340
}
336341
}
337342

@@ -356,7 +361,7 @@ public class DoublyLinkedList<Element> : CustomStringConvertible, SequenceType {
356361
} else {
357362
current = current!.next
358363
}
359-
--count
364+
count -= 1
360365
return element
361366
}
362367
}

Sources/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.6</string>
18+
<string>1.0.7</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Sources/RedBlackTree.swift

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,11 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
168168
//
169169
public func generate() -> RedBlackTree.Generator {
170170
var index = startIndex
171-
return anyGenerator {
171+
return AnyGenerator {
172172
if index < self.endIndex {
173-
return self[index++]
173+
let i: Int = index
174+
index += 1
175+
return self[i]
174176
}
175177
return nil
176178
}
@@ -219,7 +221,7 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
219221
var c: Int = 0
220222
for (k, v) in self {
221223
if block(key: k, value: v) {
222-
++c
224+
c += 1
223225
}
224226
}
225227
return Double(c) / Double(count)
@@ -398,7 +400,7 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
398400

399401
while x !== sentinel {
400402
y = x
401-
++y.order
403+
y.order += 1
402404
x = key < x.key ? x.left : x.right
403405
}
404406

@@ -413,7 +415,7 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
413415
}
414416

415417
insertCleanUp(z)
416-
++count
418+
count += 1
417419
return z
418420
}
419421

@@ -422,7 +424,8 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
422424
:description: The clean up procedure needed to maintain the RedBlackTree balance.
423425
- returns: RedBlackNode<Key, Value>
424426
*/
425-
private func insertCleanUp(var z: RedBlackNode<Key, Value>) {
427+
private func insertCleanUp(node: RedBlackNode<Key, Value>) {
428+
var z: RedBlackNode<Key, Value> = node
426429
while z.parent.isRed {
427430
if z.parent === z.parent.parent.left {
428431
let y: RedBlackNode<Key, Value> = z.parent.parent.right
@@ -483,10 +486,10 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
483486
if z !== root {
484487
var t: RedBlackNode<Key, Value> = z.parent
485488
while t !== root {
486-
--t.order
489+
t.order -= 1
487490
t = t.parent
488491
}
489-
--root.order
492+
root.order -= 1
490493
}
491494

492495

@@ -512,7 +515,7 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
512515
y.right.parent = y
513516
var t: RedBlackNode<Key, Value> = x.parent
514517
while t !== y {
515-
--t.order
518+
t.order -= 1
516519
t = t.parent
517520
}
518521
y.order = y.left.order + 1
@@ -526,7 +529,7 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
526529
if !isRed {
527530
removeCleanUp(x)
528531
}
529-
--count
532+
count -= 1
530533
return z
531534
}
532535

@@ -535,7 +538,8 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
535538
:description: After a successful removal of a node, the RedBlackTree
536539
is rebalanced by this method.
537540
*/
538-
private func removeCleanUp(var x: RedBlackNode<Key, Value>) {
541+
private func removeCleanUp(node: RedBlackNode<Key, Value>) {
542+
var x: RedBlackNode<Key, Value> = node
539543
while x !== root && !x.isRed {
540544
if x === x.parent.left {
541545
var y: RedBlackNode<Key, Value> = x.parent.right
@@ -595,7 +599,8 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
595599
:description: Finds the minimum keyed node.
596600
- returns: RedBlackNode<Key, Value>
597601
*/
598-
private func minimum(var x: RedBlackNode<Key, Value>) -> RedBlackNode<Key, Value> {
602+
private func minimum(node: RedBlackNode<Key, Value>) -> RedBlackNode<Key, Value> {
603+
var x: RedBlackNode<Key, Value> = node
599604
var y: RedBlackNode<Key, Value> = sentinel
600605
while x !== sentinel {
601606
y = x
@@ -716,7 +721,7 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
716721
private func internalCount(key: Key, node: RedBlackNode<Key, Value>, inout count: Int) {
717722
if sentinel !== node {
718723
if key == node.key {
719-
++count
724+
count += 1
720725
}
721726
internalCount(key, node: node.left, count: &count)
722727
internalCount(key, node: node.right, count: &count)
@@ -742,7 +747,8 @@ public class RedBlackTree<Key : Comparable, Value> : ProbableType, CollectionTyp
742747
:description: Traverses the Tree for the internal order statistic of a key.
743748
- returns: Int
744749
*/
745-
private func internalOrder(var x: RedBlackNode<Key, Value>) -> Int {
750+
private func internalOrder(node: RedBlackNode<Key, Value>) -> Int {
751+
var x: RedBlackNode<Key, Value> = node
746752
var r: Int = x.left.order + 1
747753
while root !== x {
748754
if x.parent.right === x {

Sources/SortedDictionary.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ public class SortedDictionary<Key : Comparable, Value where Key : Hashable> : Pr
174174
//
175175
public func generate() -> SortedDictionary.Generator {
176176
var index = startIndex
177-
return anyGenerator {
177+
return AnyGenerator {
178178
if index < self.endIndex {
179-
return self[index++]
179+
let i: Int = index
180+
index += 1
181+
return self[i]
180182
}
181183
return nil
182184
}

Sources/SortedMultiDictionary.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,11 @@ public class SortedMultiDictionary<Key : Comparable, Value where Key : Hashable>
172172
//
173173
public func generate() -> SortedMultiDictionary.Generator {
174174
var index = startIndex
175-
return anyGenerator {
175+
return AnyGenerator {
176176
if index < self.endIndex {
177-
return self[index++]
177+
let i: Int = index
178+
index += 1
179+
return self[i]
178180
}
179181
return nil
180182
}

0 commit comments

Comments
 (0)