mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 14:41:28 +00:00
Update TaskGoalListManager::GetListByID to std algos
This commit is contained in:
parent
e3dfb2f19d
commit
6399710c1d
@ -3140,7 +3140,7 @@ bool TaskGoalListManager::LoadLists()
|
||||
listIndex++;
|
||||
}
|
||||
|
||||
for(int listIndex = 0; listIndex < NumberOfLists; listIndex++) {
|
||||
for (int listIndex = 0; listIndex < NumberOfLists; listIndex++) {
|
||||
|
||||
int listID = TaskGoalLists[listIndex].ListID;
|
||||
unsigned int size = TaskGoalLists[listIndex].Size;
|
||||
@ -3157,7 +3157,7 @@ bool TaskGoalListManager::LoadLists()
|
||||
// This should only happen if a row is deleted in between us retrieving the counts
|
||||
// at the start of this method and getting to here. It should not be possible for
|
||||
// an INSERT to cause a problem, as the SELECT is used with a LIMIT
|
||||
if(results.RowCount() < size)
|
||||
if (results.RowCount() < size)
|
||||
TaskGoalLists[listIndex].Size = results.RowCount();
|
||||
|
||||
int entryIndex = 0;
|
||||
@ -3165,16 +3165,14 @@ bool TaskGoalListManager::LoadLists()
|
||||
|
||||
int entry = atoi(row[0]);
|
||||
|
||||
if(entry < TaskGoalLists[listIndex].Min)
|
||||
if (entry < TaskGoalLists[listIndex].Min)
|
||||
TaskGoalLists[listIndex].Min = entry;
|
||||
|
||||
if(entry > TaskGoalLists[listIndex].Max)
|
||||
if (entry > TaskGoalLists[listIndex].Max)
|
||||
TaskGoalLists[listIndex].Max = entry;
|
||||
|
||||
TaskGoalLists[listIndex].GoalItemEntries[entryIndex] = entry;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -3184,24 +3182,13 @@ bool TaskGoalListManager::LoadLists()
|
||||
int TaskGoalListManager::GetListByID(int ListID) {
|
||||
|
||||
// Find the list with the specified ListID and return the index
|
||||
auto it = std::find_if(TaskGoalLists.begin(), TaskGoalLists.end(),
|
||||
[ListID](const TaskGoalList_Struct &t) { return t.ListID == ListID; });
|
||||
|
||||
int FirstEntry = 0;
|
||||
int LastEntry = NumberOfLists - 1;
|
||||
|
||||
while(FirstEntry <= LastEntry) {
|
||||
int MiddleEntry = (FirstEntry + LastEntry) / 2;
|
||||
|
||||
if(ListID > TaskGoalLists[MiddleEntry].ListID)
|
||||
FirstEntry = MiddleEntry + 1;
|
||||
else if(ListID < TaskGoalLists[MiddleEntry].ListID)
|
||||
LastEntry = MiddleEntry - 1;
|
||||
else
|
||||
return MiddleEntry;
|
||||
|
||||
}
|
||||
|
||||
if (it == TaskGoalLists.end())
|
||||
return -1;
|
||||
|
||||
return std::distance(TaskGoalLists.begin(), it);
|
||||
}
|
||||
|
||||
int TaskGoalListManager::GetFirstEntry(int ListID) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user