算法用于红宝石"字符串#包括&QUOT?;红宝石、字符串、算法、QUOT

2023-09-11 05:37:46 作者:老子輝煌之時就是你避難時

有没有人能够确定哪些算法用于包括哪些内容?方法在Ruby中?例如

 HelloWorld的.INCLUDE?(你好)
 

解决方案

作为的压花的在他的回答状态,字符串#包括电话 rb_str_index 。反过来这个函数调用 rb_memsearch ,它实现了拉宾-Karp字符串搜索算法,根据这个帖子对红宝石论坛.COM

Is anyone able to pinpoint which algorithm is used for the include? method in Ruby? For example

"helloworld".include?("hello")
射手强度榜 算法一图流 v1.1

解决方案

As emboss states in his answer, String#include calls rb_str_index. This function in turn calls rb_memsearch, which implements the Rabin-Karp string search algorithm, according to this post on ruby-forum.com.

 
精彩推荐
图片推荐