Created
June 23, 2014 16:58
-
-
Save erica/481a34bc2a6f838dcdbe to your computer and use it in GitHub Desktop.
Xcode seems to hate this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct BagGenerator<T:Hashable> : Generator | |
{ | |
typealias Element = (T, Int, Int) | |
var count = 0 | |
var _backingGenerator : DictionaryGenerator<T, Int> | |
init(_ backingDictionary : Dictionary<T, Int>) { | |
_backingGenerator = backingDictionary.generate() | |
} | |
func next() -> (T, Int, Int)? | |
{ | |
var pair : (T, Int)? = _backingGenerator.next() | |
if (!pair) {return nil} | |
var tuple = (count, pair!.0, pair!.1) | |
count = count + 1 | |
return tuple | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment