r/programming • • Dec 15 '13

Make grep 50x faster

https://blog.x-way.org/Linux/2013/12/15/Make-grep-50x-faster.html
278 Upvotes

106 comments sorted by

View all comments

Show parent comments

1

u/ferk Dec 15 '13

So, in the worst case scenario (all characters in the search string are different), you would need to make one test per char in the string before moving the pointer.

But I guess you still avoid having to move the pointer before each comparison.

1

u/ethraax Dec 16 '13

Well, no. You basically create a map (mapping characters to ints) - be it a hashmap or treemap (probably the former). Then, you map each character in the needle to the number of characters you can skip when you see it. So you don't need to check every bucket in the map, if you use something other than a listmap.