Find_String for arrays
lomeraniel
Posts: 20
Does anybody know if there is a function similar to Find_String but for integer arrays? It's just to know if a number it's already in an array.
Thanks
Thanks
0
Comments
So you do not like FOR loops???? Old School????
So,
I know, I know... I better go find something useful to do...
Isn't that rather unorthodox though, using a function that was designed to find a char in a char array, to find an integer in an integer array? :-|
Sure enough, FIND_STRING(arrADA_VOLUME,"30",1) does not compile.
ERROR: C:\Programming\AMX\???.axs(975): C10585: Dimension mismatch: [0] vs. [1]
ERROR: C:\Programming\AMX\???.axs(975): C10555: Type mismatch in call for parameter [A]
(where arrADA_VOLUME is an integer array of size 13)
Thank you guys for the replies. I thought that maybe Netlinx would have a specific function to do that
I can look now for mu needle inside my haystack :P
If you know the maximum amount of possible integers and they are unique then you could put the integer in the array at the index of the integer. This would then require only one access and would run in O(1) time. It would use more memory but often that is a suitable trade off. For instance if you had an integer array of channel numbers in use, since they are guaranteed to be unique, you could define an array of 4000, and then store the number 1 at index 1, 2 at index 2 etc. If there was no integer at that location then its value would be 0 so you know that integer isn't in the array. Won't work for negative numbers though unless you come up with a clever scheme. Every time you insert a number into the array it goes into its correct element and you only need to do this to find out if the integer is in the array:
Not sure what the application is but if you tailor the way you assign integers to array elements you can find them quite a bit quicker. A hash would be perfect for what you need but you would have to write your own as there is no built in hashing function.
Paul