fix: check initalize AssociationTableData

This commit is contained in:
Marco Scholl 2023-08-06 18:03:09 +02:00
parent f7ac39c66f
commit 2934782d3c
No known key found for this signature in database

View File

@ -53,42 +53,44 @@ void AssociationTableObject::prepareBinarySearch()
// we iterate through all ASAP // we iterate through all ASAP
// the first n ASAP are sorted (strictly increasing number), these are assigning sending TSAP // the first n ASAP are sorted (strictly increasing number), these are assigning sending TSAP
// the remaining ASAP have to be all repetitions, otherwise we set sortedEntryCount to 0, which forces linear search // the remaining ASAP have to be all repetitions, otherwise we set sortedEntryCount to 0, which forces linear search
for (uint16_t idx = 0; idx < entryCount(); idx++) if(_tableData != nullptr) {
{ for (uint16_t idx = 0; idx < entryCount(); idx++)
currentASAP = getASAP(idx);
if (sortedEntryCount)
{ {
// look if the remaining ASAP exist in the previously sorted list. currentASAP = getASAP(idx);
while (lookupIdx < sortedEntryCount) if (sortedEntryCount)
{ {
lookupASAP = getASAP(lookupIdx); // look if the remaining ASAP exist in the previously sorted list.
if (currentASAP <= lookupASAP) while (lookupIdx < sortedEntryCount)
break; // while {
else lookupASAP = getASAP(lookupIdx);
lookupIdx++; if (currentASAP <= lookupASAP)
break; // while
else
lookupIdx++;
}
if (currentASAP < lookupASAP || lookupIdx >= sortedEntryCount)
{
// a new ASAP found, we force linear search
sortedEntryCount = 0;
break; // for
}
} }
if (currentASAP < lookupASAP || lookupIdx >= sortedEntryCount)
{
// a new ASAP found, we force linear search
sortedEntryCount = 0;
break; // for
}
}
else
{
// check for strictly increasing ASAP
if (currentASAP > lastASAP)
lastASAP = currentASAP;
else else
{ {
sortedEntryCount = idx; // last found index indicates end of sorted list // check for strictly increasing ASAP
idx--; // current item has to be handled as remaining ASAP if (currentASAP > lastASAP)
lastASAP = currentASAP;
else
{
sortedEntryCount = idx; // last found index indicates end of sorted list
idx--; // current item has to be handled as remaining ASAP
}
} }
} }
} // in case complete table is strictly increasing
// in case complete table is strictly increasing if (lookupIdx == 0 && sortedEntryCount == 0)
if (lookupIdx == 0 && sortedEntryCount == 0) sortedEntryCount = entryCount();
sortedEntryCount = entryCount(); }
#endif #endif
} }