cbruegg
02/16/2016, 4:14 PMk
in a long text of length n
, which would be O(nk) with indexOf
, but is O(n) with occurencesOf
. A more concrete use case: Suppose we have a large number of texts (like a search engine) we would like to run a search query against. With occurencesOf
, we could get all relevant parts of the text very efficiently, maybe get a substring of the occurence 100 chars before and after, obtaining a summary of where the word occurs.