Skip to content

Commit

Permalink
Quadratic probing.
Browse files Browse the repository at this point in the history
  • Loading branch information
lbooker42 committed Dec 22, 2023
1 parent a3a6acc commit d10c2f9
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ public static boolean findRunsHashed(

for (int chunkPosition = 0; chunkPosition < size; ++chunkPosition) {
final int outputPosition = outputPositions.get(chunkPosition);
// Increase the chance of hash collision, but reduce the linear probing needed in pathological cases.
int hashSlot = (outputPosition * 2) & context.tableMask;

int hashSlot = outputPosition & context.tableMask;
int probeOffset = 0;
do {
final int baseSlot = hashSlot * 3;
if (context.table.get(baseSlot) == UNUSED_HASH_TABLE_VALUE) {
Expand All @@ -93,8 +92,8 @@ public static boolean findRunsHashed(
overflowPointer += 2;
break;
} else {
// linear probe
hashSlot = (hashSlot + 1) & context.tableMask;
// quadratic probing to prevent excessive clustering
hashSlot = (hashSlot + (++probeOffset * probeOffset)) & context.tableMask;
}
} while (true);
}
Expand Down

0 comments on commit d10c2f9

Please sign in to comment.