mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-14 11:31:30 +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++;
|
listIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int listIndex = 0; listIndex < NumberOfLists; listIndex++) {
|
for (int listIndex = 0; listIndex < NumberOfLists; listIndex++) {
|
||||||
|
|
||||||
int listID = TaskGoalLists[listIndex].ListID;
|
int listID = TaskGoalLists[listIndex].ListID;
|
||||||
unsigned int size = TaskGoalLists[listIndex].Size;
|
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
|
// 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
|
// 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
|
// 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();
|
TaskGoalLists[listIndex].Size = results.RowCount();
|
||||||
|
|
||||||
int entryIndex = 0;
|
int entryIndex = 0;
|
||||||
@ -3165,16 +3165,14 @@ bool TaskGoalListManager::LoadLists()
|
|||||||
|
|
||||||
int entry = atoi(row[0]);
|
int entry = atoi(row[0]);
|
||||||
|
|
||||||
if(entry < TaskGoalLists[listIndex].Min)
|
if (entry < TaskGoalLists[listIndex].Min)
|
||||||
TaskGoalLists[listIndex].Min = entry;
|
TaskGoalLists[listIndex].Min = entry;
|
||||||
|
|
||||||
if(entry > TaskGoalLists[listIndex].Max)
|
if (entry > TaskGoalLists[listIndex].Max)
|
||||||
TaskGoalLists[listIndex].Max = entry;
|
TaskGoalLists[listIndex].Max = entry;
|
||||||
|
|
||||||
TaskGoalLists[listIndex].GoalItemEntries[entryIndex] = entry;
|
TaskGoalLists[listIndex].GoalItemEntries[entryIndex] = entry;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -3184,24 +3182,13 @@ bool TaskGoalListManager::LoadLists()
|
|||||||
int TaskGoalListManager::GetListByID(int ListID) {
|
int TaskGoalListManager::GetListByID(int ListID) {
|
||||||
|
|
||||||
// Find the list with the specified ListID and return the index
|
// 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;
|
if (it == TaskGoalLists.end())
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
return std::distance(TaskGoalLists.begin(), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TaskGoalListManager::GetFirstEntry(int ListID) {
|
int TaskGoalListManager::GetFirstEntry(int ListID) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user