rculfhash tests: add long hash chains tests
[urcu.git] / tests / test_urcu_hash.h
index a935e94b0a095bac4fccf9a693b18842d3f027d0..083e71c3185214b7f81dd607a5705217bd2705bb 100644 (file)
@@ -169,6 +169,8 @@ extern unsigned long init_pool_size,
        write_pool_size;
 extern int validate_lookup;
 
+extern unsigned long nr_hash_chains;
+
 extern int count_pipe[2];
 
 static inline void loop_sleep(unsigned long l)
@@ -323,7 +325,7 @@ void hashword2(
 
 #if (CAA_BITS_PER_LONG == 32)
 static inline
-unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
+unsigned long test_hash_mix(const void *_key, size_t length, unsigned long seed)
 {
        unsigned int key = (unsigned int) _key;
 
@@ -332,7 +334,7 @@ unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
 }
 #else
 static inline
-unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
+unsigned long test_hash_mix(const void *_key, size_t length, unsigned long seed)
 {
        union {
                uint64_t v64;
@@ -351,6 +353,29 @@ unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
 }
 #endif
 
+/*
+ * Hash function with nr_hash_chains != 0 for testing purpose only!
+ * Creates very long hash chains, deteriorating the hash table into a
+ * few linked lists, depending on the nr_hash_chains value. The purpose
+ * of this test is to check how the hash table behaves with hash chains
+ * containing different values, which is a rare case in a normal hash
+ * table.
+ */
+static inline
+unsigned long test_hash(const void *_key, size_t length,
+                       unsigned long seed)
+{
+       if (nr_hash_chains == 0) {
+               return test_hash_mix(_key, length, seed);
+       } else {
+               unsigned long v;
+
+               assert(length == sizeof(unsigned long));
+               v = (unsigned long) _key;
+               return v % nr_hash_chains;
+       }
+}
+
 unsigned long test_compare(const void *key1, size_t key1_len,
                            const void *key2, size_t key2_len);
 
This page took 0.023783 seconds and 4 git commands to generate.