-
Notifications
You must be signed in to change notification settings - Fork 358
+OrderedSet add filter #158 #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -494,3 +494,27 @@ extension OrderedSet { | |
| return _elements.remove(at: index) | ||
| } | ||
| } | ||
|
|
||
| extension OrderedSet { | ||
| /// Returns a new ordered set containing the values pairs of the ordered set | ||
| /// that satisfy the given predicate. | ||
| /// | ||
| /// - Parameter isIncluded: A closure that takes a value as its | ||
| /// argument and returns a Boolean value indicating whether the value | ||
| /// should be included in the returned dictionary. | ||
| /// | ||
| /// - Returns: An ordered set of the values that `isIncluded` allows. | ||
| /// | ||
| /// - Complexity: O(`count`) | ||
| @inlinable | ||
| public func filter( | ||
| _ isIncluded: (Element) throws -> Bool | ||
| ) rethrows -> Self { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation can be improved by using a temporary bitset, as in (This does not need to be implemented before this lands.)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I poked a little bit at it but we end up having to pull in quite a bunch of new uncheckedElement, _bucketCounts etc I'm not super sure if I'm implementing them right -- so leaving this as future work I guess. Happy to make a ticket for it after this lands.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, the stdlib code wouldn't directly translate -- that's just illustrating the concept. We have a separate bitset implementation within this code base, so we'd need to adapt the algorithm to use that instead. (OrderedSet.symmetricDifference is an example.) I'm happy to do this as a followup.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Followup: #163 |
||
| var result: OrderedSet = Self(minimumCapacity: _minimumCapacity) | ||
| for element in self where try isIncluded(element) { | ||
| result._appendNew(element) | ||
| } | ||
| result._checkInvariants() | ||
| return result | ||
ktoso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.