hmap: Replace 'mask' by 'shift'.
[pspp] / tests / libpspp / hmap-test.c
index c8619a0511f5b60545e70d574798c2392f477243..c7f4e5c8841c3c34e7b297b061df80f79a350838 100644 (file)
@@ -287,7 +287,18 @@ typedef size_t hash_function (int data);
 static size_t
 identity_hash (int data) 
 {
-  return data;
+  size_t hash;
+  int i;
+
+  hash = 0;
+  for (i = 0; i < 32; i++)
+    if (data & (1u << i))
+      {
+        size_t high_bit = (size_t) 1 << (sizeof (size_t) * CHAR_BIT - 1);
+        hash |= high_bit >> i;
+      }
+
+  return hash;
 }
 
 static size_t
@@ -684,7 +695,7 @@ test_insert_ordered (int max_elems, hash_function *hash)
           int max = INT_MIN;
           int j;
 
-          for (j = 0; j <= hmap.mask; j++) 
+          for (j = 0; j < hmap_n_buckets (&hmap); j++) 
             {
               int count = 0;
               struct hmap_node *node;