fast search

Jul 26, 2008 at 9:14am
Does anyone know a very fast searching function?I have to find some characters in long strings(10+ strings ,wach with 500 chars).I use now str.fin(str2); but its not fast enough...
Jul 26, 2008 at 9:33am
I doubt that you will find a better generic search function for strings than provided by your stl implementation. If you *really* think you can, I suggest that you replace the complete stl with a better version.
BTW, with 10*500 chars there will be no measurable time needed to find a substring, even if you construct the worst-case-scenario for your implementation. I therefore suggest the usage of a profiler to see what really is the reason why your program is not fast enough.
Jul 26, 2008 at 11:28am
Let's see some code! Optimization is always fun!
Jul 27, 2008 at 5:26am
Thanks.I'll try some STL things.The find algorithm complexity there is only log N..
Jul 27, 2008 at 7:56am
I would guess that you have confused some find()-functions here. The standard does not specify a complexity for finding a substring, but as can be shown easily, Omega(n*m) for a string of lenght n and a substring of length m is the worst case lower bound (which can easily achieved as upper bound as well), so my guess is that any serious STL implementation has this complexity and thus is - optimal.
Last edited on Jul 27, 2008 at 7:57am
Topic archived. No new replies allowed.