diff --git a/Algorithm.podspec b/Algorithm.podspec index 043634e..7099f5a 100644 --- a/Algorithm.podspec +++ b/Algorithm.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Algorithm' - s.version = '1.0.6' + s.version = '1.0.7' s.license = 'BSD' s.summary = 'A toolset for writing algorithms in Swift.' s.homepage = 'http://cosmicmind.io' diff --git a/Sources/Algorithm+Array.swift b/Sources/Algorithm+Array.swift index 170d50f..ff3aa1c 100644 --- a/Sources/Algorithm+Array.swift +++ b/Sources/Algorithm+Array.swift @@ -63,7 +63,7 @@ extension Array : ProbableType { for v in elements { for x in self { if v == x as! Element { - ++c + c += 1 } } } @@ -95,7 +95,7 @@ extension Array : ProbableType { var c: Int = 0 for x in self { if block(element: x) { - ++c + c += 1 } } return Double(c) / Double(count) diff --git a/Sources/Algorithm+Set.swift b/Sources/Algorithm+Set.swift index 557f013..bf195b9 100644 --- a/Sources/Algorithm+Set.swift +++ b/Sources/Algorithm+Set.swift @@ -44,7 +44,7 @@ extension Set : ProbableType { for v in elements { for x in self { if v == x as! Element { - ++c + c += 1 } } } @@ -76,7 +76,7 @@ extension Set : ProbableType { var c: Int = 0 for x in self { if block(element: x) { - ++c + c += 1 } } return Double(c) / Double(count) diff --git a/Sources/DoublyLinkedList.swift b/Sources/DoublyLinkedList.swift index e548b48..7d1a76f 100644 --- a/Sources/DoublyLinkedList.swift +++ b/Sources/DoublyLinkedList.swift @@ -71,7 +71,8 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { var x: DoublyLinkedListNode? = head while nil !== x { output += "\(x)" - if ++c != count { + c += 1 + if c != count { output += ", " } x = x!.next @@ -187,7 +188,7 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { // public func generate() -> DoublyLinkedList.Generator { cursorToFront() - return anyGenerator { + return AnyGenerator { if !self.isCursorAtBack { let element: Element? = self.cursor self.next @@ -222,7 +223,8 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { head!.previous = z } head = z - if 1 == ++count { + count += 1 + if 1 == count { current = head } else if head === current { current = head!.next @@ -240,7 +242,8 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { return nil } let element: Element? = head!.element - if 0 == --count { + count -= 1 + if 0 == count { reset() } else { head = head!.next @@ -263,7 +266,8 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { tail!.next = z } tail = z - if 1 == ++count { + count += 1 + if 1 == count { current = tail } else if tail === current { current = tail!.previous @@ -281,7 +285,8 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { return nil } let element: Element? = tail!.element - if 0 == --count { + count -= 1 + if 0 == count { reset() } else { tail = tail!.previous @@ -316,7 +321,7 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { let z: DoublyLinkedListNode = DoublyLinkedListNode(next: current, previous: current!.previous, element: element) current!.previous?.next = z current!.previous = z - ++count + count += 1 } } @@ -331,7 +336,7 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { let z: DoublyLinkedListNode = DoublyLinkedListNode(next: current!.next, previous: current, element: element) current!.next?.previous = z current!.next = z - ++count + count += 1 } } @@ -356,7 +361,7 @@ public class DoublyLinkedList : CustomStringConvertible, SequenceType { } else { current = current!.next } - --count + count -= 1 return element } } diff --git a/Sources/Info.plist b/Sources/Info.plist index 61718cd..81c339a 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.6 + 1.0.7 CFBundleSignature ???? CFBundleVersion diff --git a/Sources/RedBlackTree.swift b/Sources/RedBlackTree.swift index ca71d9f..a167424 100644 --- a/Sources/RedBlackTree.swift +++ b/Sources/RedBlackTree.swift @@ -168,9 +168,11 @@ public class RedBlackTree : ProbableType, CollectionTyp // public func generate() -> RedBlackTree.Generator { var index = startIndex - return anyGenerator { + return AnyGenerator { if index < self.endIndex { - return self[index++] + let i: Int = index + index += 1 + return self[i] } return nil } @@ -219,7 +221,7 @@ public class RedBlackTree : ProbableType, CollectionTyp var c: Int = 0 for (k, v) in self { if block(key: k, value: v) { - ++c + c += 1 } } return Double(c) / Double(count) @@ -398,7 +400,7 @@ public class RedBlackTree : ProbableType, CollectionTyp while x !== sentinel { y = x - ++y.order + y.order += 1 x = key < x.key ? x.left : x.right } @@ -413,7 +415,7 @@ public class RedBlackTree : ProbableType, CollectionTyp } insertCleanUp(z) - ++count + count += 1 return z } @@ -422,7 +424,8 @@ public class RedBlackTree : ProbableType, CollectionTyp :description: The clean up procedure needed to maintain the RedBlackTree balance. - returns: RedBlackNode */ - private func insertCleanUp(var z: RedBlackNode) { + private func insertCleanUp(node: RedBlackNode) { + var z: RedBlackNode = node while z.parent.isRed { if z.parent === z.parent.parent.left { let y: RedBlackNode = z.parent.parent.right @@ -483,10 +486,10 @@ public class RedBlackTree : ProbableType, CollectionTyp if z !== root { var t: RedBlackNode = z.parent while t !== root { - --t.order + t.order -= 1 t = t.parent } - --root.order + root.order -= 1 } @@ -512,7 +515,7 @@ public class RedBlackTree : ProbableType, CollectionTyp y.right.parent = y var t: RedBlackNode = x.parent while t !== y { - --t.order + t.order -= 1 t = t.parent } y.order = y.left.order + 1 @@ -526,7 +529,7 @@ public class RedBlackTree : ProbableType, CollectionTyp if !isRed { removeCleanUp(x) } - --count + count -= 1 return z } @@ -535,7 +538,8 @@ public class RedBlackTree : ProbableType, CollectionTyp :description: After a successful removal of a node, the RedBlackTree is rebalanced by this method. */ - private func removeCleanUp(var x: RedBlackNode) { + private func removeCleanUp(node: RedBlackNode) { + var x: RedBlackNode = node while x !== root && !x.isRed { if x === x.parent.left { var y: RedBlackNode = x.parent.right @@ -595,7 +599,8 @@ public class RedBlackTree : ProbableType, CollectionTyp :description: Finds the minimum keyed node. - returns: RedBlackNode */ - private func minimum(var x: RedBlackNode) -> RedBlackNode { + private func minimum(node: RedBlackNode) -> RedBlackNode { + var x: RedBlackNode = node var y: RedBlackNode = sentinel while x !== sentinel { y = x @@ -716,7 +721,7 @@ public class RedBlackTree : ProbableType, CollectionTyp private func internalCount(key: Key, node: RedBlackNode, inout count: Int) { if sentinel !== node { if key == node.key { - ++count + count += 1 } internalCount(key, node: node.left, count: &count) internalCount(key, node: node.right, count: &count) @@ -742,7 +747,8 @@ public class RedBlackTree : ProbableType, CollectionTyp :description: Traverses the Tree for the internal order statistic of a key. - returns: Int */ - private func internalOrder(var x: RedBlackNode) -> Int { + private func internalOrder(node: RedBlackNode) -> Int { + var x: RedBlackNode = node var r: Int = x.left.order + 1 while root !== x { if x.parent.right === x { diff --git a/Sources/SortedDictionary.swift b/Sources/SortedDictionary.swift index 791169a..d3c25c2 100644 --- a/Sources/SortedDictionary.swift +++ b/Sources/SortedDictionary.swift @@ -174,9 +174,11 @@ public class SortedDictionary : Pr // public func generate() -> SortedDictionary.Generator { var index = startIndex - return anyGenerator { + return AnyGenerator { if index < self.endIndex { - return self[index++] + let i: Int = index + index += 1 + return self[i] } return nil } diff --git a/Sources/SortedMultiDictionary.swift b/Sources/SortedMultiDictionary.swift index 13f5c5b..aefb24c 100644 --- a/Sources/SortedMultiDictionary.swift +++ b/Sources/SortedMultiDictionary.swift @@ -172,9 +172,11 @@ public class SortedMultiDictionary // public func generate() -> SortedMultiDictionary.Generator { var index = startIndex - return anyGenerator { + return AnyGenerator { if index < self.endIndex { - return self[index++] + let i: Int = index + index += 1 + return self[i] } return nil } diff --git a/Sources/SortedMultiSet.swift b/Sources/SortedMultiSet.swift index 7695b05..8247a35 100644 --- a/Sources/SortedMultiSet.swift +++ b/Sources/SortedMultiSet.swift @@ -155,9 +155,11 @@ public class SortedMultiSet : ProbableType, CollectionType // public func generate() -> SortedMultiSet.Generator { var index = startIndex - return anyGenerator { + return AnyGenerator { if index < self.endIndex { - return self[index++] + let i: Int = index + index += 1 + return self[i] } return nil } @@ -202,7 +204,7 @@ public class SortedMultiSet : ProbableType, CollectionType var c: Int = 0 for x in self { if block(element: x) { - ++c + c += 1 } } return Double(c) / Double(count) @@ -331,13 +333,13 @@ public class SortedMultiSet : ProbableType, CollectionType let x: Element = self[i] let y: Element = set[j] if x < y { - ++i + i += 1 } else if y < x { - ++j + j += 1 } else { s.insert(x) - ++i - ++j + i += 1 + j += 1 } } return s @@ -361,10 +363,10 @@ public class SortedMultiSet : ProbableType, CollectionType tree.removeInstanceValueForKey(x) count = tree.count } else if y < x { - ++j + j += 1 } else { - ++i - ++j + i += 1 + j += 1 } } } @@ -386,21 +388,23 @@ public class SortedMultiSet : ProbableType, CollectionType let y: Element = set[j] if x < y { s.insert(x) - ++i + i += 1 } else if y < x { s.insert(y) - ++j + j += 1 } else { s.insert(x) - ++i - ++j + i += 1 + j += 1 } } while k > i { - s.insert(self[i++]) + s.insert(self[i]) + i += 1 } while l > j { - s.insert(set[j++]) + s.insert(set[j]) + j += 1 } return s } @@ -417,17 +421,18 @@ public class SortedMultiSet : ProbableType, CollectionType let x: Element = self[i] let y: Element = set[j] if x < y { - ++i + i += 1 } else if y < x { insert(y) - ++j + j += 1 } else { - ++i - ++j + i += 1 + j += 1 } } while l > j { - insert(set[j++]) + insert(set[j]) + j += 1 } } @@ -447,16 +452,17 @@ public class SortedMultiSet : ProbableType, CollectionType let y: Element = set[j] if x < y { s.insert(x) - ++i + i += 1 } else if y < x { - ++j + j += 1 } else { - ++i - ++j + i += 1 + j += 1 } } while k > i { - s.insert(self[i++]) + s.insert(self[i]) + i += 1 } return s } @@ -473,13 +479,13 @@ public class SortedMultiSet : ProbableType, CollectionType let x: Element = self[i] let y: Element = set[j] if x < y { - ++i + i += 1 } else if y < x { - ++j + j += 1 } else { tree.removeInstanceValueForKey(x) count = tree.count - ++j + j += 1 } } } @@ -500,20 +506,22 @@ public class SortedMultiSet : ProbableType, CollectionType let y: Element = set[j] if x < y { s.insert(x) - ++i; + i += 1 } else if y < x { s.insert(y) - ++j + j += 1 } else { i += countOf(x) j += set.countOf(y) } } while k > i { - s.insert(self[i++]) + s.insert(self[i]) + i += 1 } while l > j { - s.insert(set[j++]) + s.insert(set[j]) + j += 1 } return s } @@ -532,17 +540,18 @@ public class SortedMultiSet : ProbableType, CollectionType let x: Element = self[i] let y: Element = set[j] if x < y { - ++i + i += 1 } else if y < x { insert(y) - ++j + j += 1 } else { remove(x) - ++j + j += 1 } } while l > j { - insert(set[j++]) + insert(set[j]) + j += 1 } } @@ -558,9 +567,9 @@ public class SortedMultiSet : ProbableType, CollectionType let x: Element = self[i] let y: Element = set[j] if x < y { - --j + j -= 1 } else if y < x { - --i + i -= 1 } else { return false } diff --git a/Sources/SortedSet.swift b/Sources/SortedSet.swift index e21491a..75e8fd6 100644 --- a/Sources/SortedSet.swift +++ b/Sources/SortedSet.swift @@ -155,9 +155,11 @@ public class SortedSet : ProbableType, CollectionType, Com // public func generate() -> SortedSet.Generator { var index = startIndex - return anyGenerator { + return AnyGenerator { if index < self.endIndex { - return self[index++] + let i: Int = index + index += 1 + return self[i] } return nil } @@ -202,7 +204,7 @@ public class SortedSet : ProbableType, CollectionType, Com var c: Int = 0 for x in self { if block(element: x) { - ++c + c += 1 } } return Double(c) / Double(count) @@ -331,13 +333,13 @@ public class SortedSet : ProbableType, CollectionType, Com let x: Element = self[i] let y: Element = set[j] if x < y { - ++i + i += 1 } else if y < x { - ++j + j += 1 } else { s.insert(x) - ++i - ++j + i += 1 + j += 1 } } return s @@ -360,10 +362,10 @@ public class SortedSet : ProbableType, CollectionType, Com if x < y { remove(x) } else if y < x { - ++j + j += 1 } else { - ++i - ++j + i += 1 + j += 1 } } } @@ -385,21 +387,23 @@ public class SortedSet : ProbableType, CollectionType, Com let y: Element = set[j] if x < y { s.insert(x) - ++i + i += 1 } else if y < x { s.insert(y) - ++j + j += 1 } else { s.insert(x) - ++i - ++j + i += 1 + j += 1 } } while k > i { - s.insert(self[i++]) + s.insert(self[i]) + i += 1 } while l > j { - s.insert(set[j++]) + s.insert(set[j]) + j += 1 } return s } @@ -411,7 +415,8 @@ public class SortedSet : ProbableType, CollectionType, Com public func unionInPlace(set: SortedSet) { var j: Int = set.count while 0 != j { - insert(set[--j]) + j -= 1 + insert(set[j]) } } @@ -431,16 +436,17 @@ public class SortedSet : ProbableType, CollectionType, Com let y: Element = set[j] if x < y { s.insert(x) - ++i + i += 1 } else if y < x { - ++j + j += 1 } else { - ++i - ++j + i += 1 + j += 1 } } while k > i { - s.insert(self[i++]) + s.insert(self[i]) + i += 1 } return s } @@ -457,12 +463,12 @@ public class SortedSet : ProbableType, CollectionType, Com let x: Element = self[i] let y: Element = set[j] if x < y { - ++i + i += 1 } else if y < x { - ++j + j += 1 } else { remove(x) - ++j + j += 1 } } } @@ -483,20 +489,22 @@ public class SortedSet : ProbableType, CollectionType, Com let y: Element = set[j] if x < y { s.insert(x) - ++i + i += 1 } else if y < x { s.insert(y) - ++j + j += 1 } else { - ++i - ++j + i += 1 + j += 1 } } while k > i { - s.insert(self[i++]) + s.insert(self[i]) + i += 1 } while l > j { - s.insert(set[j++]) + s.insert(set[j]) + j += 1 } return s } @@ -515,17 +523,18 @@ public class SortedSet : ProbableType, CollectionType, Com let x: Element = self[i] let y: Element = set[j] if x < y { - ++i + i += 1 } else if y < x { insert(y) - ++j + j += 1 } else { remove(x) - ++j + j += 1 } } while l > j { - insert(set[j++]) + insert(set[j]) + j += 1 } } @@ -541,9 +550,9 @@ public class SortedSet : ProbableType, CollectionType, Com let x: Element = self[i] let y: Element = set[j] if x < y { - --j + j -= 1 } else if y < x { - --i + i -= 1 } else { return false } diff --git a/Tests/SortedDictionaryTests.swift b/Tests/SortedDictionaryTests.swift index a77466c..5003040 100644 --- a/Tests/SortedDictionaryTests.swift +++ b/Tests/SortedDictionaryTests.swift @@ -87,7 +87,7 @@ class SortedDictionaryTests: XCTestCase { XCTAssert(5 == x.value, "Test failed.") } - for (var i: Int = s.endIndex - 1; i >= s.startIndex; --i) { + for i in 0..= s.startIndex; --i) { + for i in 0..