我学习字符串搜索算法,现在,不知道是什么算法用于.NET String.Contains功能为例。 反射显示,使用此功能,但我不知道它的名字的含义。
私有静态外部INT InternalFindNLSStringEx(IntPtr的处理,字符串localeName,诠释旗,串源,诠释sourceCount,诠释了startIndex,目标字符串,INT targetCount);
解决方案
我猜,当然,但我会说,这只是天真的字符串搜索的实现,具有O(N * M)的性能。
现在,这可能是惊人错误的,但在MSDN不指定此方法的性能,所以它不是安全的假设有更好的表现。
此外,最先进的模式搜索方法是比较专业的特定字符串类型,虽然有的是的更好的通用搜索算法,以实现它 String.IndexOf
是不必要的优化一些。
原因很简单:如果你的需要的一个有效的模式搜索,那么你会实现你自己的,无论如何,量身定制,以满足您的特定数据。因此,有没有必要实施一些花哨的通用库。
![排得更好VS估得更准VS搜的更全 推荐 广告 搜索 算法间到底有什么区别](https://p.xsw88.cn/allimgs/daicuo/20230904/6102.png)
I'm studying string searching algorithms now and wondering what algorithm is used for .NET String.Contains function for example. Reflector shows that this function is used but I have no idea what its name means.
private static extern int InternalFindNLSStringEx(IntPtr handle, string localeName, int flags, string source, int sourceCount, int startIndex, string target, int targetCount);
解决方案
I’m guessing of course but I’d say that it’s just the naive string search implementation, having O(n*m) performance.
Now, this might be phenomenally wrong but the MSDN doesn’t specify the performance of this method so it’s not safe to assume a better performance.
Furthermore, most advanced pattern searching methods are quite specialized for certain string types and while there are better general-purpose search algorithms, implementing it in String.IndexOf
is somewhat of an unnecessary optimization.
The reason is simple: if you require an efficient pattern search then you’ll implement your own anyway, custom-tailored to fit your particular data. So there’s no need to implement something fancy in the general-purpose library.
相关推荐
最新文章