MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PPic_GetIndexFromID

Function PPic_GetIndexFromID

Descent3/PilotPicsAPI.cpp:723–748  ·  view source on GitHub ↗

------------------------------------- PPic_GetIndexFromID Purpose: Returns the file index into the Pilot_id_to_offset list for the given id, -1 if not found. -------------------------------------

Source from the content-addressed store, hash-verified

721// list for the given id, -1 if not found.
722// -------------------------------------
723int 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}

Callers 1

PPic_GetOffsetByIDFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected