| 1 | ###User Defined Function### |
|---|
| 2 | _ArrayBinarySearch |
|---|
| 3 | |
|---|
| 4 | ###Description### |
|---|
| 5 | Uses the binary search algorithm to search through a 1D or 2D array |
|---|
| 6 | |
|---|
| 7 | ###Syntax### |
|---|
| 8 | #include <Array.au3> |
|---|
| 9 | _ArrayBinarySearch ( Const ByRef $aArray, $vValue [, $iStart = 0 [, $iEnd = 0 [, $iColumn = 0]]] ) |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | ###Parameters### |
|---|
| 13 | @@ParamTable@@ |
|---|
| 14 | $aArray |
|---|
| 15 | Array to search |
|---|
| 16 | $vValue |
|---|
| 17 | Value to find |
|---|
| 18 | $iStart |
|---|
| 19 | [optional] Index of array to start searching at |
|---|
| 20 | $iEnd |
|---|
| 21 | [optional] Index of array to stop searching at |
|---|
| 22 | $iColumn |
|---|
| 23 | [optional] Column of array to search |
|---|
| 24 | @@End@@ |
|---|
| 25 | |
|---|
| 26 | ###ReturnValue### |
|---|
| 27 | @@ReturnTable@@ |
|---|
| 28 | Success: the index that value was found at. |
|---|
| 29 | Failure: -1 and sets the @error flag to non-zero. |
|---|
| 30 | @error: 1 - $aArray is not an array |
|---|
| 31 | 2 - $vValue outside of array min/max values |
|---|
| 32 | 3 - $vValue was not found in array |
|---|
| 33 | 4 - $iStart is greater than $iEnd |
|---|
| 34 | 5 - $aArray is not a 1D or 2D array |
|---|
| 35 | 6 - $aArray is empty |
|---|
| 36 | 7 - $iColumn outside array bounds |
|---|
| 37 | @@End@@ |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | ###Remarks### |
|---|
| 41 | When performing a binary search on an array of items, the array (specified column if 2D) MUST be sorted before the search is done. Otherwise undefined results will be returned. |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | ###Related### |
|---|
| 45 | _ArrayFindAll, _ArraySearch |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | ###Example### |
|---|
| 49 | @@IncludeExample@@ |
|---|