? faster looping ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

faster looping

the most common way to loop through an array is this: DEF SEARCH(ARRAY,LOOK) FOR I = 0 TO LEN(ARRAY)-1 IF ARRAY[I]==LOOK THEN RETURN I NEXT END but this is very inefficient speed-wise. but an alternative, which is 25% faster is bilinear search: DEF BILINEARSEARCH(ARRAY,LOOK) VAR L = LEN(ARRAY)-1,L2=L/2 FOR I = 0 TO L2 IF ARRAY[L2+I]==LOOK THEN RETURN L2+I IF ARRAY[L2-I]==LOOK THEN RETURN L2-I NEXT IF ARRAY[L]==LOOK THEN RETURN L RETURN -1 END
Author
DFrost
Updated
Rating
3 votes
Categories
Keywords
5 Comment(s) DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength this is a parody Y_ack Y_ack ?? DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength you referenced this and called it a parody Y_ack Y_ack I called super search a parody of this page. DFrost DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength OH OK!