Skip to content

Commit 62cf45f

Browse files
author
mkandil
committed
add return self and init
1 parent 4f31435 commit 62cf45f

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

stdlib/public/Cxx/CxxDictionary.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public protocol CxxDictionary<Key, Value> {
2525
associatedtype Size: BinaryInteger
2626
associatedtype InsertionResult
2727

28+
init()
29+
2830
/// Do not implement this function manually in Swift.
2931
func __findUnsafe(_ key: Key) -> RawIterator
3032

@@ -61,24 +63,6 @@ extension CxxDictionary {
6163
return iter.pointee.second
6264
}
6365
}
64-
65-
func filter(
66-
_ isIncluded: (_ key: Key, _ value: Value) throws -> Bool
67-
) rethrows -> [Key: Value] {
68-
var filteredDictionary: [Key: Value] = [:]
69-
var iterator = __beginUnsafe(Key)
70-
let endIterator = __endUnsafe()
71-
72-
while iterator != endIterator {
73-
let pair = iterator.pointee
74-
if try isIncluded(pair.first, pair.second) {
75-
filteredDictionary[pair.first] = pair.second
76-
}
77-
iterator = iterator.successor()
78-
}
79-
80-
return filteredDictionary
81-
}
8266
}
8367

8468
extension CxxDictionary {
@@ -107,4 +91,22 @@ extension CxxDictionary {
10791
}
10892
}
10993
}
94+
95+
public func filter(
96+
_ isIncluded: (_ key: Key, _ value: Value) throws -> Bool
97+
) rethrows -> Self {
98+
var filteredDictionary: Self.init()
99+
var iterator = __beginUnsafe()
100+
let endIterator = __endUnsafe()
101+
102+
while iterator != endIterator {
103+
let pair = iterator.pointee
104+
if try isIncluded(pair.first, pair.second) {
105+
filteredDictionary[pair.first] = pair.second
106+
}
107+
iterator = iterator.successor()
108+
}
109+
110+
return filteredDictionary
111+
}
110112
}

0 commit comments

Comments
 (0)