Skip to content

Commit

Permalink
Use quadratic probing for collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Jun 8, 2019
1 parent efa79c6 commit 07be9ce
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Words.Native.Core/Hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace Words
return true;
}

next_index(index);
next_index(index, i);
}

return false;
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace Words
return false;
}

next_index(index);
next_index(index, i);
}

insert_new(index, key, value);
Expand Down Expand Up @@ -161,17 +161,17 @@ namespace Words
return;
}

next_index(index);
next_index(index, i);
}
}

void next_index(int& index) const
void next_index(int& index, int c) const
{
++index;
index += 1 + (2 * c);
int n = static_cast<int>(buckets_.size());
if (index == n)
if (index >= n)
{
index = 0;
index = index % n;
}
}
};
Expand Down

0 comments on commit 07be9ce

Please sign in to comment.