1. find_all() And More
- Posted by euphoric (admin) Sep 29, 2010
- 1143 views
a = { 0, 1, 2, 3, 0 } find_all( 0, a ) -- is { 1, 5 }
Is there a lib function that will let me do a find for "anything but 0" such that it returns { 2, 3, 4 }?
I guess I could do:
a = { 0, 1, 2, 3, 0 } b = a = 0 find_all( 0, b ) -- is now { 2, 3, 4 }
I just want what's fastest. :)
2. Re: find_all() And More
- Posted by jeremy (admin) Sep 29, 2010
- 1110 views
sequence r = remove_all(0, { 0, 10, 0, 20, 0, 30, 0 }) r -- { 10, 20, 30 }
Jeremy
3. Re: find_all() And More
- Posted by euphoric (admin) Sep 29, 2010
- 1068 views
sequence r = remove_all(0, { 0, 10, 0, 20, 0, 30, 0 }) r -- { 10, 20, 30 }
Jeremy
I need indexes, not values.
4. Re: find_all() And More
- Posted by dcole Sep 29, 2010
- 1083 views
a = { 0, 1, 2, 3, 0 } find_all( 0, a ) -- is { 1, 5 }
Is there a lib function that will let me do a find for "anything but 0" such that it returns { 2, 3, 4 }?
I guess I could do:
a = { 0, 1, 2, 3, 0 } b = a = 0 find_all( 0, b ) -- is now { 2, 3, 4 }
I just want what's fastest. :)
Hello euphoric,
The first example is the fastest.
Don Cole
5. Re: find_all() And More
- Posted by euphoric (admin) Sep 29, 2010
- 1078 views
a = { 0, 1, 2, 3, 0 } find_all( 0, a ) -- is { 1, 5 }
Is there a lib function that will let me do a find for "anything but 0" such that it returns { 2, 3, 4 }?
I guess I could do:
a = { 0, 1, 2, 3, 0 } b = a = 0 find_all( 0, b ) -- is now { 2, 3, 4 }
I just want what's fastest. :)
Hello euphoric,
The first example is the fastest.
Don Cole
Those two examples above are not doing the same thing, so it's not apples to apples. :)
6. Re: find_all() And More
- Posted by mattlewis (admin) Sep 29, 2010
- 1087 views
a = { 0, 1, 2, 3, 0 } find_all( 0, a ) -- is { 1, 5 }
Is there a lib function that will let me do a find for "anything but 0" such that it returns { 2, 3, 4 }?
I guess I could do:
a = { 0, 1, 2, 3, 0 } b = a = 0 find_all( 0, b ) -- is now { 2, 3, 4 }
I just want what's fastest. :)
I'd try something like this:
constant a = { 0, 1, 2, 3, 0 } function find_all_but( object needle, sequence haystack ) integer ix = 1 integer jx sequence found = {} while jx with entry do for i = ix to jx - 1 do found &= i end for ix = jx + 1 entry jx = find( needle, haystack, ix ) end while return found end function ? find_all_but( 0, a )
Matt
7. Re: find_all() And More
- Posted by dcole Sep 29, 2010
- 1066 views
Sorry I miss read your question.
Do you want the index to include the zeros?
Ex. {0,0,0,7,12,17}={3,4,5}
or exclude the zeros?
Ex.{0,0,0,7,12,17}={1,2,3}
Don Cole
8. Re: find_all() And More
- Posted by euphoric (admin) Sep 29, 2010
- 1111 views
I'd try something like this:
Here's a benchmarking program for it.
include std/sequence.e include std/console.e include std/search.e sequence a = { 0, 1, 2, 3, 0 }, b b = repeat_pattern( a, 500 ) function find_all_but( object needle, sequence haystack ) integer ix = 1 integer jx sequence found = {} while jx with entry do for i = ix to jx - 1 do found &= i end for ix = jx + 1 entry jx = find( needle, haystack, ix ) end while return found end function atom timer = 3 + time() sequence x atom c = 0 while time() < timer do c+=1 x = find_all_but( 0, a ) end while ?c sequence g timer = 3+time() c=0 g=a=0 -- here's the cheat? while time() < timer do c+=1 x = find_all( 0, g ) end while ?c wait_key()
If I put g=a=0 INSIDE the loop, then your code is waaaaAAAAAyyy faster.
So, huh?
9. Re: find_all() And More
- Posted by DerekParnell (admin) Sep 29, 2010
- 1127 views
I'd try something like this:
Here's a tweak to Matt's code ...
constant a = { 0, 1, 2, 3, 0 } function find_all_but( object needle, sequence haystack ) integer ix = 1 integer jx integer kx = 0 while jx with entry do for i = ix to jx - 1 do kx += 1 haystack[kx] = i end for ix = jx + 1 entry jx = find( needle, haystack, ix ) end while for i = ix to length(haystack) do kx += 1 haystack[kx] = i end for return haystack[1 .. kx] end function ? find_all_but( 0, a )
10. Re: find_all() And More
- Posted by mattlewis (admin) Sep 29, 2010
- 1088 views
I'd try something like this:
Here's a tweak to Matt's code ...
D'oh! I always do that...
Matt
Forked into: find_all_not() and using a pattern sequence