swift-algorithms
swift-algorithms copied to clipboard
Add methods for finding subsequences in a collection
Work in Progress
Description
Methods for finding the first, last, or all ranges of a given subsequence.
Detailed Design
TK
Documentation Plan
Guide and docs to come…
Test Plan
Initial unit tests included.
Source Impact
This is an additive change only.
Checklist
- [ ] I've added at least one test that validates that my change is working, if appropriate
- [ ] I've followed the code style of the rest of the project
- [ ] I've read the Contribution Guidelines
- [ ] I've updated the documentation if necessary
You could probably generalize the Collection.firstRange(of:) method (and therefore BidirectionalCollection.lastRange(of:) too) with an equivalence predicate and/or letting the collections differ in Element type. The given predicate would be allowed to throw.
Have you seen @milseman ’s CollectionSearcher prototype? https://forums.swift.org/t/prototype-protocol-powered-generic-trimming-searching-splitting/29415
I wonder if that would serve as a useful base to include in this library. We could implement things like the generic 2-way search algorithm and Z algorithm mentioned in that post.
@CTMacUser and @karwa Absolutely, still exploring the API surfaces here. Thanks!
@swift-ci Please test
This functionality is handled by the string-processing package.