Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
libp2p: remove unused variable count in NodeTable::nearestNodeEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Jan 13, 2016
1 parent b7835f6 commit a1f3302
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions libp2p/NodeTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,67 +220,54 @@ vector<shared_ptr<NodeEntry>> NodeTable::nearestNodeEntries(NodeID _target)
static unsigned lastBin = s_bins - 1;
unsigned head = distance(m_node.id, _target);
unsigned tail = head == 0 ? lastBin : (head - 1) % s_bins;

map<unsigned, list<shared_ptr<NodeEntry>>> found;
unsigned count = 0;


// if d is 0, then we roll look forward, if last, we reverse, else, spread from d
if (head > 1 && tail != lastBin)
while (head != tail && head < s_bins && count < s_bucketSize)
while (head != tail && head < s_bins)
{
Guard l(x_state);
for (auto const& n: m_state[head].nodes)
if (auto p = n.lock())
{
if (count < s_bucketSize)
found[distance(_target, p->id)].push_back(p);
else
break;
found[distance(_target, p->id)].push_back(p);
}
if (count < s_bucketSize && tail)

if (tail > 0)
for (auto const& n: m_state[tail].nodes)
if (auto p = n.lock())
{
if (count < s_bucketSize)
found[distance(_target, p->id)].push_back(p);
else
break;
found[distance(_target, p->id)].push_back(p);
}

head++;
if (tail)
tail--;
}
else if (head < 2)
while (head < s_bins && count < s_bucketSize)
while (head < s_bins)
{
Guard l(x_state);
for (auto const& n: m_state[head].nodes)
if (auto p = n.lock())
{
if (count < s_bucketSize)
found[distance(_target, p->id)].push_back(p);
else
break;
found[distance(_target, p->id)].push_back(p);
}
head++;
}
else
while (tail > 0 && count < s_bucketSize)
while (tail > 0)
{
Guard l(x_state);
for (auto const& n: m_state[tail].nodes)
if (auto p = n.lock())
{
if (count < s_bucketSize)
found[distance(_target, p->id)].push_back(p);
else
break;
found[distance(_target, p->id)].push_back(p);
}
tail--;
}

vector<shared_ptr<NodeEntry>> ret;
for (auto& nodes: found)
for (auto const& n: nodes.second)
Expand Down

0 comments on commit a1f3302

Please sign in to comment.