Created
September 4, 2016 19:57
-
-
Save lizixroy/3063d06069fbfd398a63664f614deb08 to your computer and use it in GitHub Desktop.
RxSwift-article-9.swift
This file contains hidden or 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
public mutating func insert(element: T) -> BagKey { | |
_nextKey = _nextKey &+ 1 | |
#if DEBUG | |
_nextKey = _nextKey % 20 | |
#endif | |
if _nextKey == 0 { | |
_uniqueIdentity = Identity() | |
} | |
let key = BagKey(uniqueIdentity: _uniqueIdentity, key: _nextKey) | |
if _key0 == nil { | |
_key0 = key | |
_value0 = element | |
return key | |
} | |
_onlyFastPath = false | |
if _key1 == nil { | |
_key1 = key | |
_value1 = element | |
return key | |
} | |
if _dictionary != nil { | |
_dictionary![key] = element | |
return key | |
} | |
if _pairs.count < arrayDictionaryMaxSize { | |
_pairs.append(key: key, value: element) | |
return key | |
} | |
if _dictionary == nil { | |
_dictionary = [:] | |
} | |
_dictionary![key] = element | |
return key | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment