Skip to content

Commit

Permalink
Merge pull request #255 from OpenKNX/fix-check-init-of-assoc-table
Browse files Browse the repository at this point in the history
Fix check init of assoc table
  • Loading branch information
thelsing authored Aug 9, 2023
2 parents f7ac39c + 2934782 commit bf9c3ff
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions src/knx/association_table_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,44 @@ void AssociationTableObject::prepareBinarySearch()
// we iterate through all ASAP
// 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
for (uint16_t idx = 0; idx < entryCount(); idx++)
{
currentASAP = getASAP(idx);
if (sortedEntryCount)
if(_tableData != nullptr) {
for (uint16_t idx = 0; idx < entryCount(); idx++)
{
// look if the remaining ASAP exist in the previously sorted list.
while (lookupIdx < sortedEntryCount)
{
lookupASAP = getASAP(lookupIdx);
if (currentASAP <= lookupASAP)
break; // while
else
lookupIdx++;
}
if (currentASAP < lookupASAP || lookupIdx >= sortedEntryCount)
currentASAP = getASAP(idx);
if (sortedEntryCount)
{
// a new ASAP found, we force linear search
sortedEntryCount = 0;
break; // for
// look if the remaining ASAP exist in the previously sorted list.
while (lookupIdx < sortedEntryCount)
{
lookupASAP = getASAP(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
}
}
}
else
{
// check for strictly increasing 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
// check for strictly increasing 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
if (lookupIdx == 0 && sortedEntryCount == 0)
sortedEntryCount = entryCount();
// in case complete table is strictly increasing
if (lookupIdx == 0 && sortedEntryCount == 0)
sortedEntryCount = entryCount();
}
#endif
}

Expand Down

0 comments on commit bf9c3ff

Please sign in to comment.