Skip to content

Commit a5376fe

Browse files
author
Qi Chen
committed
add check for deleted and dup.
1 parent 94b2713 commit a5376fe

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

AnnService/inc/Core/SPANN/ExtraDynamicSearcher.h

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,38 +1592,28 @@ namespace SPTAG::SPANN {
15921592
if (p_stats) p_stats->m_exSetUpLatency = 0;
15931593

15941594
COMMON::QueryResultSet<ValueType>& queryResults = *((COMMON::QueryResultSet<ValueType>*) & p_queryResults);
1595-
if (queryResults.GetResult(0)->VID != -1) {
1596-
int i = 0, j = 1;
1597-
while (i < queryResults.GetResultNum()) {
1595+
if (queryResults.GetResult(0)->VID != -1)
1596+
{
1597+
int head = 0;
1598+
for (int i = 0; i < queryResults.GetResultNum(); ++i)
1599+
{
15981600
SPTAG::BasicResult* ri = queryResults.GetResult(i);
1599-
if (ri->VID == -1 || m_versionMap->Delete(ri->VID)) {
1600-
bool found = false;
1601-
SPTAG::BasicResult* rj = nullptr;
1602-
while (j < queryResults.GetResultNum())
1601+
if (ri->VID != -1 && !m_versionMap->Deleted(ri->VID) && !p_exWorkSpace->m_deduper.CheckAndSet(ri->VID))
1602+
{
1603+
if (head != i)
16031604
{
1604-
rj = queryResults.GetResult(j++);
1605-
if (rj->VID == -1) continue;
1606-
if (!m_versionMap->Delete(rj->VID)) {
1607-
found = true;
1608-
break;
1609-
} else {
1610-
rj->VID = -1;
1611-
rj->Dist = MaxDist;
1612-
}
1613-
}
1614-
if (found) {
1615-
*ri = *rj;
1616-
rj->VID = -1;
1617-
rj->Dist = MaxDist;
1618-
i++;
1619-
} else {
1605+
SPTAG::BasicResult* rhead = queryResults.GetResult(head);
1606+
*rhead = *ri;
16201607
ri->VID = -1;
16211608
ri->Dist = MaxDist;
1622-
break;
16231609
}
1624-
} else {
1625-
i++;
1626-
if (j <= i) j = i + 1;
1610+
1611+
++head;
1612+
}
1613+
else
1614+
{
1615+
ri->VID = -1;
1616+
ri->Dist = MaxDist;
16271617
}
16281618
}
16291619
}
@@ -1734,7 +1724,7 @@ namespace SPTAG::SPANN {
17341724
BasicResult* head = headResults.GetResult(p_exWorkSpace->m_ri);
17351725
while (!foundResult && p_exWorkSpace->m_pi < p_exWorkSpace->m_postingIDs.size()) {
17361726
if (head && head->VID != -1 && p_exWorkSpace->m_ri <= p_exWorkSpace->m_pi) {
1737-
if (!m_versionMap->Deleted(head->VID) &&
1727+
if (!m_versionMap->Deleted(head->VID) && !p_exWorkSpace->m_deduper.CheckAndSet(head->VID) &&
17381728
(p_exWorkSpace->m_filterFunc == nullptr || p_exWorkSpace->m_filterFunc(p_spann->GetMetadata(head->VID)))) {
17391729
queryResults.AddPoint(head->VID, head->Dist);
17401730
foundResult = true;
@@ -1766,7 +1756,7 @@ namespace SPTAG::SPANN {
17661756
}
17671757
}
17681758
while (!foundResult && head && head->VID != -1) {
1769-
if (!m_versionMap->Deleted(head->VID) &&
1759+
if (!m_versionMap->Deleted(head->VID) && !p_exWorkSpace->m_deduper.CheckAndSet(head->VID) &&
17701760
(p_exWorkSpace->m_filterFunc == nullptr || p_exWorkSpace->m_filterFunc(p_spann->GetMetadata(head->VID)))) {
17711761
queryResults.AddPoint(head->VID, head->Dist);
17721762
foundResult = true;

0 commit comments

Comments
 (0)