OrderedMap

public struct OrderedMap<Key, Value> where Key : Hashable

Dictionary with ordered enumeration of keys. Keys are sorted by increasing recency of creation/mutation. So, keys at the beginning were created/updated the longest time ago and the towards the end were recently created/updated.

  • The number of key-value pairs in the dictionary.

    Declaration

    Swift

    public var count: Int { get }
  • List containing keys of the dictionary in increasing order of recency.

    Declaration

    Swift

    public var keys: [Key] { get }
  • Updates the value stored in the dictionary for the given key, or adds a new key-value pair if the key does not exist. The updated key is moved to the end of the sorted list of keys as it would now be the most recently updated key.

    Complexity

    O(n), where n is the number of key-value pairs in the dictionary.

    Declaration

    Swift

    @discardableResult
    public mutating func updateValue(_ value: Value, forKey key: Key) -> Value?
  • Initialize an empty data-structure.

    Declaration

    Swift

    public init()
  • Initialize the data-structure from the list of tuples. Later keys in the list override older keys.

    Declaration

    Swift

    public init(_ map: [Key : Value])
  • Removes the given key and its associated value from the dictionary.

    Complexity

    O(n), where n is the number of key-value pairs in the dictionary.

    Declaration

    Swift

    public mutating func removeValue(forKey key: Key) -> Value?
  • Get or set the value of the given key. defaultValue is not evaluated unless needed.

    Declaration

    Swift

    public subscript(key: Key, default defaultValue: @autoclosure() -> Value) -> Value
  • Get or set the value of the given key.

    Declaration

    Swift

    public subscript(key: Key) -> Value? { get set }
  • Removes all key-value pairs from the dictionary.

    Declaration

    Swift

    public mutating func removeAll()