GLBasic forum

Feature request => IDE/Syntax => Topic started by: Dark Schneider on 2010-Nov-22

Title: SEARCHARRAY command?
Post by: Dark Schneider on 2010-Nov-22
We have a SORTARRAY function, but we have not a SEARCHARRAY function, it would be good one like the SORTARRAY one, accepting TYPEs with the same syntax, using the first member variable as compare for equal, or allowing to use a custom function with the syntax something like:

Code (glbasic) Select
FUNCTION compare: BYREF a, value%#$
   IF a.member%#$=value%#$ then return TRUE
   return FALSE
ENDFUNCTION


I think a basic function like a SEARCH should be available in GLBasic API.
Title: Re: SEARCHARRAY command?
Post by: Kitty Hello on 2010-Nov-22
good idea.
Title: Re: SEARCHARRAY command?
Post by: Dark Schneider on 2010-Nov-22
One thing I forgot to mention, the SEARCHARRAY can return:

1) TRUE or FALSE.
2) Position of the item (the first found), -1 if it doesn't exists.
3) An array with the positions of all items that satisfies the comparison.

Which one could/should be used?.
Title: Re: SEARCHARRAY command?
Post by: MrTAToad on 2010-Nov-23
A binary search routine would be the best - as long as the array is sorted.  If its not, then some sort of linear search would be needed...
Title: Re: SEARCHARRAY command?
Post by: Kitty Hello on 2010-Nov-23
I'd return the first index of the found item (using C++ operator == )
Title: Re: SEARCHARRAY command?
Post by: Dark Schneider on 2010-Nov-23
Quote from: Kitty Hello on 2010-Nov-23
I'd return the first index of the found item (using C++ operator == )

Yes, I think that is the best option too.