Skip to content

Commit ed82668

Browse files
committed
add wildcard matching
1 parent 514ed29 commit ed82668

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

wildcard-matching/README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,62 @@
1+
## Convert to [Regular Expression Matching](../regular-expression-matching)
12

2-
## TODO
3-
* write down thinking
3+
* `?` -> `.`
4+
* `*` -> `.*`
45

6+
This should work, yet, it exceeds the time limited.
7+
8+
## Checkpoint / Timemachine
9+
10+
On modern OS, you can go back to some time you saved if your OS meets some problem.
11+
such technology also can be used to solve this problem.
12+
13+
```
14+
S
15+
16+
[ a a b ]
17+
18+
[ a * b * ]
19+
20+
P
21+
22+
23+
P is *, save current state.
24+
```
25+
26+
`P` goes on to next
27+
28+
```
29+
30+
This state means * matches nothing
31+
32+
S
33+
34+
[ a a b ]
35+
36+
[ a * b * ]
37+
38+
P
39+
40+
```
41+
42+
a mismatch found, `P != S`, so rollback to checkpoint.
43+
44+
```
45+
This state means * matches a
46+
47+
S
48+
49+
[ a a b ]
50+
51+
[ a * b * ]
52+
53+
P
54+
```
55+
56+
Each `*` will save to a checkpoint, and retry from nothing until a match is found.
57+
58+
59+
### Remaining tail
60+
61+
Sometimes, `S` meets the end, but the `P` not.
62+
In this case, just to check remaining chars in `P` are all `*`.

0 commit comments

Comments
 (0)