Swift
Collections
Dictionary
Dictionary
Value type 이다.
@frozen public struct Dictionary<Key, Value> where Key : Hashable
subscript(_:)
O(N)
count
O(N)
contains(where:)
O(N)
contains(_:) method는 없다. (key로 바로 참조하면 알 수 있기 때문)
index(forKey:)
평균 O(1)
bridged NSDictionary으로 Wrap된 경우 O(N)
mapValues(_:)
O(N)
compactMapValues(_:)
O(M+N)
N은 기존 Dictionary의 크기
M은 결과 Dictionary의 크기
remove(at:), removeValue(forKey:), removeAll(keepingCapacity:)
O(N)
popFirst()
평균 O(1)
rereversed()
O(N)
출처
github.com/apple/swift/blob/main/stdlib/public/core/Dictionary
댓글남기기