[libc-commits] [PATCH] D86162: [libc] Add two-way strstr algorithm.
Chris Gyurgyik via Phabricator via libc-commits
libc-commits at lists.llvm.org
Tue Aug 18 12:00:40 PDT 2020
cgyurgyik created this revision.
cgyurgyik added reviewers: sivachandra, abrachet.
Herald added subscribers: libc-commits, ecnelises, tschuett, mgorny.
Herald added a project: libc-project.
cgyurgyik requested review of this revision.
[libc] This adds the two-way strstr algorithm, and uses it when the length of the haystack is above a certain threshold, for which I picked at random (currently). I look forward to your reviews.
Rationale: The two-way matching algorithm allows for string matching in linear time and constant space complexity. However, it (1) adds a lot of complexity to the code, and (2) Is probably worse when the haystack and needle are small. When this "change-over" occurs for when Two Way >> Brute Force, I am currently unsure. I could write a few benchmarks and get a rough estimate, but looking for input first on the best way to approach this.
As far as testing, both the brute force and the two-way algorithms pass the unit tests and the fuzz test for strstr.
rG LLVM Github Monorepo
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 15265 bytes
Desc: not available
More information about the libc-commits