Skip to content

Commit

Permalink
make sure keys are imported in order
Browse files Browse the repository at this point in the history
  • Loading branch information
Machx committed Mar 10, 2021
1 parent a107724 commit 7e72d9a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/Konkyo/Data Structures/RollingDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ public struct RollingDictionary<Key:Hashable,Value>:ExpressibleByDictionaryLiter
/// - Parameter elements: The Dictionary literal for key/value pairs to initialize the structure with.
public init(dictionaryLiteral elements: (Key, Value)...) {
_limit = Int.max
_dictionary = Dictionary<Key,Value>(uniqueKeysWithValues: elements)
_keys = Array(_dictionary.keys)
// do it this way to preserve ordering
_dictionary = Dictionary<Key,Value>()
_keys = [Key]()
for (key,value) in elements {
_dictionary[key] = value
_keys.append(key)
}
}

public subscript(key: Key) -> Value? {
Expand Down

0 comments on commit 7e72d9a

Please sign in to comment.