Count occurrences of a substring: Difference between revisions

m
→‎{{header|Quackery}}: tweaked commentary
(Added Quackery.)
m (→‎{{header|Quackery}}: tweaked commentary)
Line 2,525:
usefsm ] ] is find$ ( $ $ --> n )</lang>
 
<code>find$</code> builds a finite state machine to search for m, (an O(m³) operation), then uses it to search in n with O(n). Rather than use <code>find$</code>, and repeatedly build the same fsm, we will define a word <code>findall$</code> which returns a nest (i.e. list) of positions of m within n. (It actually returns the positionpositions of the end of the substring, relative to (for the first instance) the start of the string, or (for subsequent instances) the end of the previous instance of the substring.)
 
<lang Quackery> [ over size 0 = iff
1,493

edits