Closed timvermeulen closed 1 year ago
There could probably be optimizations based on count
.
For example, if other
’s count
is larger than self
, then there’s no point in iterating through self
since it could never contain a larger collection as a subsequence. That’s just a base case that could be checked up front. However, this can also happen in the middle of the algorithm. For example, if we had a self.count
of 20, and an other.count
of 5, if we ever get a starting index (matchStart
) past the 15th element, we can then just return nil
since we can’t fit a subsequence of 5 with only 4 elements remaining.
@mdznr Such an optimization would only work for a RandomAccessCollection
, and these are not specialized for those indexing semantics (yet.)
This functionality is handled by the string-processing package.
Find the location of a subsequence in a collection.
firstRange(of:)
lastRange(of:)
contains(_:)
Checklist