On Wed, Oct 12, 2011 at 11:24 AM, I wrote: > L=: 'label' > D=: ,'p<label>0'8!:2 i.1e6 ... > F=:1 :0 NB. x: label, m: max labels to find, y: target > : > b=. 2*m*#x NB. block size to search (smaller for testing, larger > for typical use) > r=. i.0 NB. result > for_block. |: b -~/\@(] <. [ * 0 1 +/i.@>.@%~) #y do. > if. m-:#r do. return. end. > 'z b'=. block > r=. r, ({.~ (m-#r) <. #)z+x I.@E. y{~z+i.b > end. > )
Please note that this has a bug in it. The problem is that it does not properly deal with the case where a label straddles a block boundary. The fix is to extend each block by (#label)-1 characters. For example (untested code, sorry): F=:1 :0 NB. x: label, m: max labels to find, y: target : b=. 2*m*#x NB. block size to search r=. i.0 NB. result ov=. 0, (#x)-1 NB. block overlap adjustment for_block. |: b -~/\@(] <. ov + [ * 0 1 +/i.@>.@%~) #y do. if. m-:#r do. return. end. 'z b'=. block r=. r, ({.~ (m-#r) <. #)z+x I.@E. y{~z+i.b end. ) FYI, -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm