Re: Fast "locate" function
- Posted by euman at bellsouth.net
Dec 06, 2001
This is the best Ive seen in a while....
function find_all_2(object test, sequence data)
integer ix, jx, len
sequence result
result = {}
ix = 1
len = length(data)
jx = find( test, data[ix..len] )
while jx do
result &= ix+jx-1
ix += jx
jx = find( test, data[ix..len] )
end while
return result
end function
Thank Matt Lewis for this one.
If this isnt what your looking for or want to gander "look at" some other
interesting twist "code" on this same subject then search prior post on the
mailing list
keyword = find_all
Euman
euman at bellsouth.net
----- Original Message -----
From: "Alan Oxley" <fizzpop at icon.co.za>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, December 06, 2001 3:07 AM
Subject: Fast "locate" function
>
> Any elegant coder out there have a fast "locate" function, similar to
> "find",
> but returns the location of a defined byte sequence inside a large byte
> sequence..?
> As in, something without a "compare" or "match" inside a loop...
> "find" seems to be the answer, but it does not work for me. Example:
>
> sequence s1, s2
> integer i1
> s1 = {#00,#00,#00,#30}
> s2 = {#27,#20,#00,#00,#00,#30,#20,#40}
> i1 = find(s1,s2)
> printf(1,"Marker found at location %d\n",i1)
> -- i1 should be 3, but its 0, as in nothing found.
>
> I'm attempting to extract some 27K records from a 6M(mainframe) file, by
> looking for s1.
> The records are variable length, so my current (slow) solution is a nested
> loop containing "compare". The only consistency in my data file is the byte
> sequence s1....
> Any help would be appreciated.
>
> Alan
>
>
>
>
|
Not Categorized, Please Help
|
|