------------------------------------- PPic_GetIndexFromID Purpose: Returns the file index into the Pilot_id_to_offset list for the given id, -1 if not found. -------------------------------------
| 721 | // list for the given id, -1 if not found. |
| 722 | // ------------------------------------- |
| 723 | int PPic_GetIndexFromID(int id) { |
| 724 | // do a binary search for the id,return -1 if not found |
| 725 | int min = 0, max = PilotPic_count - 1; |
| 726 | int index_to_check; |
| 727 | int sort_index, sorted_val; |
| 728 | |
| 729 | while (1) { |
| 730 | index_to_check = (min + max) / 2; |
| 731 | sort_index = Sorted_Pilot_id_to_offset[index_to_check]; |
| 732 | sorted_val = Pilot_id_to_offset[sort_index].id; |
| 733 | |
| 734 | if (sorted_val == id) { |
| 735 | // found it! |
| 736 | return sort_index; |
| 737 | } |
| 738 | |
| 739 | if (min >= max) // exhausted search |
| 740 | break; |
| 741 | |
| 742 | if (sorted_val > id) // search key after check key |
| 743 | min = index_to_check + 1; |
| 744 | else // search key before check key |
| 745 | max = index_to_check - 1; |
| 746 | } |
| 747 | return -1; |
| 748 | } |
no outgoing calls
no test coverage detected