swift-algorithms icon indicating copy to clipboard operation
swift-algorithms copied to clipboard

Add methods for finding subsequences in a collection

Open natecook1000 opened this issue 5 years ago • 4 comments

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

natecook1000 avatar Nov 05 '20 20:11 natecook1000

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.

CTMacUser avatar Nov 21 '20 05:11 CTMacUser

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.

karwa avatar Nov 26 '20 08:11 karwa

@CTMacUser and @karwa Absolutely, still exploring the API surfaces here. Thanks!

natecook1000 avatar Dec 01 '20 21:12 natecook1000

@swift-ci Please test

natecook1000 avatar Jul 29 '21 18:07 natecook1000

This functionality is handled by the string-processing package.

natecook1000 avatar Jul 20 '23 18:07 natecook1000