Skip to content

Conversation

@advikkabra
Copy link
Collaborator

Implemented the Knuth-Morris-Pratt algorithm for str.count(), similar to the str.find() implementation. This should improve speed significantly in many cases.

@advikkabra
Copy link
Collaborator Author

advikkabra commented Feb 12, 2024

As an aside, as recommended by #2355, we can improve these algorithms further and benchmark them if need be.
There may be variations of the Boyer-Moore algorithm which work better, as the issue suggests, but I have used KMP as it is previously used for the string find method. I can work on testing and benchmarking them if the current algorithms are to be changed.

CPython implementation
Blog post explaining more

@advikkabra
Copy link
Collaborator Author

@certik Could you review this PR?

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@advikkabra thank you for this PR. I think it looks great, thanks for implementing the more advanced algorithm, both at compile time and runtime.

@certik certik force-pushed the new-str-attributes branch from c9ecf24 to 12c88e7 Compare February 17, 2024 16:51
@certik certik enabled auto-merge February 17, 2024 16:51
@certik certik merged commit 960fdda into lcompilers:main Feb 17, 2024
@advikkabra advikkabra deleted the new-str-attributes branch February 18, 2024 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants