From 84c0bfe7b03d454e68f3c6496beadfa4bbb956be Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Fri, 18 Dec 2015 13:43:50 +0000 Subject: [PATCH] Fix two small bugs in the hopscotch hash that meant that moving elements near the end of the array sometimes caused them to become lost. --- hash_table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hash_table.h b/hash_table.h index 951bd2d..aaae772 100644 --- a/hash_table.h +++ b/hash_table.h @@ -288,7 +288,7 @@ static int PREFIX(_insert)(PREFIX(_table) *table, return 1; } /* If this cell is full, try the next one. */ - for (unsigned int i=0 ; i<32 ; i++) + for (unsigned int i=1 ; i<33 ; i++) { PREFIX(_table_cell) second = PREFIX(_table_lookup)(table, hash+i); @@ -374,7 +374,7 @@ static void PREFIX(_table_move_second)(PREFIX(_table) *table, // Look at each offset defined by the jump table to find the displaced location. int hop = __builtin_ffs(jump); PREFIX(_table_cell) hopCell = - PREFIX(_table_lookup)(table, MAP_TABLE_HASH_VALUE(emptyCell->value) + hop); + PREFIX(_table_lookup)(table, (emptyCell - table->table) + hop); emptyCell->value = hopCell->value; emptyCell->secondMaps &= ~(1 << (hop-1)); if (0 == hopCell->secondMaps)