Question: Fast Unsorted Array Search - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question: Fast Unsorted Array Search (
/showthread.php?tid=431540)
Question: Fast Unsorted Array Search -
Maxips2 - 18.04.2013
How could I search a value in an unsorted array, in a fast way ?
I was thinking about using binary tree but I don't know if its possible in an unsorted array.
Any suggestions?
Re: Question: Fast Unsorted Array Search -
Babul - 18.04.2013
only a linear search, if the script doesnt know anything about the content.
are there any constraints of the values in the array?
like, is each value unique, is there a min/max limit?
Re: Question: Fast Unsorted Array Search -
Maxips2 - 18.04.2013
Quote:
Originally Posted by Babul
only a linear search, if the script doesnt know anything about the content.
are there any constraints of the values contained in the array?
like, is each value unique, is there a min/max limit?
|
Nope, each index stores an ID, and the script doesn't know anything about it.
About limits, no maximum (well 2^31-1 as we can only work with 32-bit variables), minimum would be 1 or 0.
I think that y_bintree can help me here with generating a binary tree for an array, however I have no experience with that library at all, ill search some info in YSI wiki or in the script itself.