SEARCHARRAY command?

Previous topic - Next topic

Dark Schneider

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.

Kitty Hello


Dark Schneider

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?.

MrTAToad

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...

Kitty Hello

I'd return the first index of the found item (using C++ operator == )

Dark Schneider

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.