InsertionOrderedDictionary
public struct InsertionOrderedDictionary<Key, Value> where Key : Hashable
extension InsertionOrderedDictionary : RandomAccessCollection
extension InsertionOrderedDictionary : Sequence
extension InsertionOrderedDictionary : CustomReflectable
extension InsertionOrderedDictionary
: CustomStringConvertible, CustomDebugStringConvertible
extension InsertionOrderedDictionary : Hashable where Value : Hashable
extension InsertionOrderedDictionary : Equatable where Value : Equatable
extension InsertionOrderedDictionary
: Decodable where Key : Decodable, Value : Decodable
extension InsertionOrderedDictionary : Encodable
where Key : Encodable, Value : Encodable
A Dictionary with a deterministic sequence traversal order determined by the order in which keys are added.
-
The elements of
self
.Declaration
Swift
public private(set) var elements: [KeyValuePair<Key, Value>]
-
A mapping from keys to indices in
elements
.Declaration
Swift
public private(set) var indexForKey: [Key : Int]
-
The element type of a dictionary, just like a tuple containing an individual key-value pair, but nominal.
Declaration
Swift
public typealias Element = KeyValuePair<Key, Value>
-
The position of a key-value pair in a dictionary.
Declaration
Swift
public typealias Index = Keys.Index
-
Undocumented
Declaration
Swift
public typealias Keys = Projections<[Element], Element.ProjectKey>
-
Undocumented
Declaration
Swift
public var keys: Keys { get }
-
Undocumented
Declaration
Swift
public typealias Values = Projections<[Element], Element.ProjectValue>
-
Undocumented
Declaration
Swift
public var values: Values { get set }
-
Creates an instance equivalent to
source
.Declaration
Swift
public init(_ source: [Key : Value])
-
Creates an empty instance.
Declaration
Swift
public init()
-
Creates an empty dictionary with preallocated space for at least the specified number of elements.
Declaration
Swift
public init(minimumCapacity: Int)
-
Creates a new dictionary from the key-value pairs in the given sequence.
The keys in the result are ordered in the same order as in
uniqueKeysWithValues
.Declaration
-
Creates a new dictionary from the key-value pairs in the given sequence, using a combining closure to determine the value for any duplicate keys.
The keys in the result are ordered according to their first appearance in
keysAndValues
.Declaration
-
Creates a new dictionary whose keys are the groupings returned by the given closure and whose values are arrays of the elements that returned each key.
The keys in the result are ordered according to their first appearance in
source
.Declaration
-
Returns a new dictionary containing the key-value pairs of the dictionary that satisfy the given predicate.
Declaration
Swift
@available(swift 4.0) public func filter( _ isIncluded: (Element) throws -> Bool ) rethrows -> InsertionOrderedDictionary
-
Accesses the value associated with the given key, producing
nil
when the value of a key not in the dictionary is read, and erasing the key ifnil
is written.Complexity
amortized O(1) unless a key is deleted, in which case O(count
).Declaration
Swift
public subscript(key: Key) -> Value? { get set }
-
Accesses the value for
key
, ordefaultValue
no such key exists in the dictionary, on write first insertingkey
with valuedefaultValue
if it does not exist in the dictionary.Declaration
Swift
public subscript( key: Key, default defaultValue: @autoclosure () -> Value ) -> Value
-
Returns a new dictionary containing the keys of this dictionary with the values transformed by the given closure.
Declaration
Swift
public func mapValues<T>( _ transform: (Value) throws -> T ) rethrows -> InsertionOrderedDictionary<Key, T>
-
Returns a new dictionary containing only the key-value pairs that have non-
nil
values as the result of transformation by the given closure.Declaration
Swift
public func compactMapValues<T>( _ transform: (Value) throws -> T? ) rethrows -> InsertionOrderedDictionary<Key, T>
-
Updates the value stored in the dictionary for the given key and returns the old value, or adds a new key-value pair if the key does not exist and returns nil .
Declaration
Swift
public mutating func updateValue( _ newValue: Value, forKey key: Key ) -> Value?
-
Merges the key-value pairs in the given sequence into the dictionary, using a combining closure to determine the value for any duplicate keys.
Declaration
-
Creates a dictionary by merging key-value pairs in a sequence into the dictionary, using a combining closure to determine the value for duplicate keys.
Declaration
-
Creates a dictionary by merging the given dictionary into this dictionary, using a combining closure to determine the value for duplicate keys.
Declaration
Swift
public func merging( _ other: Self, uniquingKeysWith combine: (Value, Value) throws -> Value ) rethrows -> Self
-
Removes and returns the key-value pair at
i
.Complexity
O(count
). -
Removes the given key and its associated value from the dictionary.
Complexity
O(count
)Declaration
Swift
public mutating func removeValue(forKey key: Key) -> Value?
-
Removes all key-value pairs from the dictionary.
Declaration
Swift
public mutating func removeAll( keepingCapacity keepCapacity: Bool = false )
-
An iterator over the members of a
InsertionOrderedDictionary<Key, Value>
.Declaration
Swift
public typealias Iterator = Array<Element>.Iterator
-
The total number of key-value pairs that the dictionary can contain without allocating new storage.
Declaration
Swift
public var capacity: Int { get }
-
Reserves enough space to store the specified number of key-value pairs.
Declaration
Swift
public mutating func reserveCapacity(_ minimumCapacity: Int)
-
The position of the first element in a nonempty dictionary.
Declaration
Swift
public var startIndex: Index { get }
-
The dictionary’s “past the end” position—that is, the position one greater than the last valid subscript argument.
Declaration
Swift
public var endIndex: Index { get }
-
Returns the index for the given key.
Declaration
Swift
public func index(forKey key: Key) -> Index?
-
Accesses the key-value pair at the specified position.
-
The number of key-value pairs in the dictionary.
Declaration
Swift
public var count: Int { get }
-
A Boolean value that indicates whether the dictionary is empty.
Declaration
Swift
public var isEmpty: Bool { get }
-
Returns an iterator over the dictionary’s key-value pairs.
Declaration
Swift
public func makeIterator() -> Iterator
-
A mirror that reflects the dictionary.
Declaration
Swift
public var customMirror: Mirror { get }
-
A string that represents the contents of the dictionary.
Declaration
Swift
public var description: String { get }
-
A string that represents the contents of the dictionary, suitable for debugging.
Declaration
Swift
public var debugDescription: String { get }
-
Creates a new dictionary by decoding from the given decoder.
Declaration
Swift
public init(from decoder: Decoder) throws
-
Encodes the contents of this dictionary into the given encoder.
Declaration
Swift
public func encode(to encoder: Encoder) throws