This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What algorithm used for searching substring


On Wed, Oct 9, 2013 at 12:52 PM, Habibutsu <habibutsu@gmail.com> wrote:
> When i use "std::string::find" it's mean that in actually will be used
> "std::search" or will be used more effective algorithm (for example
> Knuth–Morris–Pratt)

I think std::basic_string::find use brute force here
http://gcc.gnu.org/viewcvs/gcc/trunk/libstdc++-v3/include/bits/basic_string.tcc?revision=195701&view=markup

IMHO, please notice that worst cases for brute force algorithm *may*
be uncommon in daily use, while the brute force probablly wins KMP in
it's best case, which *may* be common in daily use.


-- 
Tim Shen


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]