Java indexOf function more efficient than Rabin-Karp? Search Efficiency of Text

后端 未结 7 534
面向向阳花
面向向阳花 2020-12-20 11:47

I posed a question to Stackoverflow a few weeks ago about a creating an efficient algorithm to search for a pattern in a large chunk of text. Right now I am using the St

7条回答
  •  一个人的身影
    2020-12-20 12:39

    Not only simply try a longer static string, but try generating random long strings and inserting the search target into a random location each time. Without randomizing it, you will see a fixed result for indexOf.

    EDITED: Random is the wrong concept. Most text is not truly random. But you would need a lot of different long strings to be effective, and not just testing the same String multiple times. I am sure there are ways to extract "random" large Strings from an even larger text source, or something like that.

提交回复
热议问题