Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Aho-Corasick #66

Merged
merged 1 commit into from
Feb 22, 2024
Merged

Update Aho-Corasick #66

merged 1 commit into from
Feb 22, 2024

Conversation

meooow25
Copy link
Owner

@meooow25 meooow25 commented Feb 20, 2024

The primary change is constructing strictly.
Got hacked on CSES with a large case. The new solution (includes I/O and overhead of other parts of the solution, mind you) takes ~65% of the previous solution's time on this case. But it is also slower in other cases, where being lazy is better.

- Build the trie strictly. This has an up front cost, but saves time
  later when matching.
- Force the result early in the alter function in insertTAC. Improves
  construction times a bit.
- Replace the ACLink type with Maybe (ACNode a). This lets us use the
  value from IM.lookup directly, and simplifies the code. Doesn't seem
  to have an observable effect on benchmarks.
- Update the NFData instances to not rnf outs. It was there since random
  benchmarks are unlikely to hit O(n^2), but we can do without it.
- Use ByteString instead of ByteString.Char8. Char doesn't give use
  anything here.
- Update complexities to be more accurate.
- Other small implementation changes.
@meooow25 meooow25 merged commit d121780 into master Feb 22, 2024
1 check passed
@meooow25 meooow25 deleted the aho2 branch February 22, 2024 02:08
github-actions bot pushed a commit that referenced this pull request Feb 22, 2024
Soumik Sarkar: Update Aho-Corasick (#66)

- Build the trie strictly. This has an up front cost, but saves time
  later when matching.
- Force the result early in the alter function in insertTAC. Improves
  construction times a bit.
- Replace the ACLink type with Maybe (ACNode a). This lets us use the
  value from IM.lookup directly, and simplifies the code. Doesn't seem
  to have an observable effect on benchmarks.
- Update the NFData instances to not rnf outs. It was there since random
  benchmarks are unlikely to hit O(n^2), but we can do without it.
- Use ByteString instead of ByteString.Char8. Char doesn't give use
  anything here.
- Update complexities to be more accurate.
- Other small implementation changes.
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.

1 participant