7
votes
Accepted
Aho-Corasick algorithm implemented in C
references
Woo hoo! You cite a reference for the underlying algorithm. Excellent.
In the header comments for match(), nit: Minor grammar / typos.
includes
...
5
votes
Accepted
A different approach to string pattern matching algorithm
A couple of comments on your answer:
Code style
If you've already stored the pattern.length(), why keep calling the method? Just be consistent and use that ...
5
votes
Accepted
Separating data from string representation of objects, with added extras
Type hinting
Instead of having helpdocs declare the types of function parameters, why not go with type hinting?
Complexity
Your code currently has too many moving parts. You define 2 different ...
4
votes
Structural Pattern Matching syntax to match a value in a list
Like you, I am excited about Python's new pattern matching. Unfortunately,
I don't think your use case is a good fit. Every tool has strengths
and weaknesses. In this specific situation, ordinary <...
4
votes
Check if a given string matches a wildcard pattern
The code you wrote can be improved in lots of places. I'll go through it from top to bottom.
#include <stdio.h>
#include <string.h>
Perfect until now. ...
4
votes
Accepted
Wildcard Matching: LeetCode 44
Nice code, good identifiers.
if (tryMatch(s, sPos + loop, p, pPos + 1, max)) {
In starMatch, don't we maybe get to ...
4
votes
Aho-Corasick algorithm implemented in C
To add to @J_H's good points:
Only include what's required:
In "aho_corasick.h", <stddef.h> should suffice for ...
3
votes
Pattern matching with predicates support
Improve the API
When I read v >>= m, I see that v was the function parameter, but what is ...
3
votes
Wildcard Matching: LeetCode 44
Make sure you match the required API
Ideally, you wouldn't use a class Solution for this, and just create free functions. However, if you are given an API you have ...
3
votes
pattern matching coding challenge
your code looks fine - some minor issues:
test driven developement
if you have clear requirements, write test to validate them.
"The method should pass the following tests"
i hope you have ...
3
votes
Structural Pattern Matching syntax to match a value in a list
I like your implementation as a whole, I do not think the if part you mentioned is the problem. [_, *middle, _] is a bigger ...
3
votes
Accepted
Find repeating pattern in a string
main()
void
main()
Oops: that's not a standard signature for main(). You probably meant <...
3
votes
Accepted
Match Multiple Patterns in 2D Array and Return (x,y) Coordinates of the highest pattern
Your solution is overly complicated and not very efficient. First, since we are dealing with strings, you can use std::string::find() to check if a row from ...
3
votes
How to refactor the boolean logic of this F# function?
This could be simplified by using straightforward composition:
...
2
votes
How to refactor the boolean logic of this F# function?
I would avoid using Option .IsNone and .Value, mainly because .Value will throw an exception ...
2
votes
How to refactor the boolean logic of this F# function?
Lets focus on filterByPattern.
A Predicate is a function returning a boolean ('T -> bool). Since the predicate host most of ...
2
votes
Check if a given string matches a wildcard pattern
Move your main() to the bottom, so you don't have to declare other functions, it's also less prone to errors.
'*' is not called ...
2
votes
Separating data from string representation of objects, with added extras
Here's an implementation whose major endeavour, when compared with your implementation as well as that of the accepted answer, is separation of parsing and execution. It's unclear whether this is ...
2
votes
Accepted
State monad and pattern matching on data constructors
In general, you would extract the state using get and then case-match on it, like so:
...
2
votes
Accepted
Stepwise nested pattern mattching with exceptions
After tinkering around, I settled on this solution using optics and some type classes:
...
2
votes
Stepwise nested pattern mattching with exceptions
The amount of repeated code isn't large, I don't think that's worth worrying about. It does seem like you've got a lot of buried cases making your nice ...
1
vote
Accepted
Wildcard Matching: LeetCode 44 Attempt 2
Move your code out of class Solution
I modified the method slightly.
If you no longer feel bound by the interface imposed on you by LeetCode, then I would not put ...
1
vote
Accepted
Cardinal to ordinal numbers in F# code reuse
You can combine both cases with an if .. then .. else ..
...
1
vote
PartialOrd of Rust Enums based on encapsulated data
You can match on a tuple, which flattens everything:
...
1
vote
pattern matching coding challenge
null
Nulls can be useful, however they can also be more trouble than their worth.
Do you really need to use null, or could you get away with using "" ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pattern-matching × 16c++ × 4
c × 3
python × 2
java × 2
strings × 2
haskell × 2
f# × 2
performance × 1
beginner × 1
algorithm × 1
programming-challenge × 1
c++11 × 1
parsing × 1
time-limit-exceeded × 1
reinventing-the-wheel × 1
functional-programming × 1
rust × 1
regex × 1
error-handling × 1
c++17 × 1
template-meta-programming × 1
enum × 1
state × 1