Skip to content

Instantly share code, notes, and snippets.

@lizixroy
Created September 4, 2016 19:57
Show Gist options
  • Save lizixroy/3063d06069fbfd398a63664f614deb08 to your computer and use it in GitHub Desktop.
Save lizixroy/3063d06069fbfd398a63664f614deb08 to your computer and use it in GitHub Desktop.
RxSwift-article-9.swift
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