diff options
author | Eric Anholt <eric@anholt.net> | 2014-11-25 15:37:08 -0800 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2014-11-25 15:37:53 -0800 |
commit | 5297879bf3b3828c10eb4c5a18c6405ef5a420ee (patch) | |
tree | 79ebfac2c9a852d88ff93af6d40569f67fd6ddfe | |
parent | 474ac0a4e73366d6f88daf75ea7af53244d62756 (diff) |
Make helpers for creating hash tables and sets of strings.
This fixes warnings when building the testsuite, due to char * vs void
* in prototypes.
-rw-r--r-- | fnv_hash.h | 10 | ||||
-rw-r--r-- | tests/collision.c | 2 | ||||
-rw-r--r-- | tests/destroy_callback.c | 2 | ||||
-rw-r--r-- | tests/insert_and_lookup.c | 2 | ||||
-rw-r--r-- | tests/remove_null.c | 2 | ||||
-rw-r--r-- | tests/replacement.c | 2 | ||||
-rw-r--r-- | tests/set/destroy_callback.c | 2 | ||||
-rw-r--r-- | tests/set/insert_and_lookup.c | 2 | ||||
-rw-r--r-- | tests/set/null_remove.c | 2 | ||||
-rw-r--r-- | tests/set/replacement.c | 2 |
10 files changed, 19 insertions, 9 deletions
@@ -1,5 +1,6 @@ /* * Copyright © 2009 Intel Corporation + * Copyright © 2014 Broadcom * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -32,4 +33,13 @@ uint32_t fnv1_hash_string(const char *key); uint32_t fnv1_hash_data(const void *data, size_t size); + int string_key_equals(const void *a, const void *b); + +#define hash_table_create_for_string() \ + hash_table_create((uint32_t (*)(const void *key))fnv1_hash_string, \ + string_key_equals) + +#define set_create_for_string() \ + set_create((uint32_t (*)(const void *key))fnv1_hash_string, \ + string_key_equals) diff --git a/tests/collision.c b/tests/collision.c index 7156257..ba5365c 100644 --- a/tests/collision.c +++ b/tests/collision.c @@ -41,7 +41,7 @@ main(int argc, char **argv) uint32_t bad_hash = 5; int i; - ht = hash_table_create(fnv1_hash_string, string_key_equals); + ht = hash_table_create_for_string(); /* Add #1 and verify search. */ hash_table_insert_pre_hashed(ht, bad_hash, str1, NULL); diff --git a/tests/destroy_callback.c b/tests/destroy_callback.c index 785bd4d..03a2a14 100644 --- a/tests/destroy_callback.c +++ b/tests/destroy_callback.c @@ -53,7 +53,7 @@ main(int argc, char **argv) struct hash_table *ht; uint32_t hash_str1 = fnv1_hash_string(str1); - ht = hash_table_create(fnv1_hash_string, string_key_equals); + ht = hash_table_create_for_string(); hash_table_insert_pre_hashed(ht, hash_str1, str1, NULL); hash_table_insert(ht, str2, NULL); diff --git a/tests/insert_and_lookup.c b/tests/insert_and_lookup.c index 5643bac..1e6ba0b 100644 --- a/tests/insert_and_lookup.c +++ b/tests/insert_and_lookup.c @@ -40,7 +40,7 @@ main(int argc, char **argv) uint32_t hash_str1 = fnv1_hash_string(str1); struct hash_entry *entry; - ht = hash_table_create(fnv1_hash_string, string_key_equals); + ht = hash_table_create_for_string(); hash_table_insert_pre_hashed(ht, hash_str1, str1, NULL); hash_table_insert(ht, str2, NULL); diff --git a/tests/remove_null.c b/tests/remove_null.c index bdb549a..d040a0f 100644 --- a/tests/remove_null.c +++ b/tests/remove_null.c @@ -36,7 +36,7 @@ main(int argc, char **argv) { struct hash_table *ht; - ht = hash_table_create(fnv1_hash_string, string_key_equals); + ht = hash_table_create_for_string(); hash_table_remove_entry(ht, NULL); diff --git a/tests/replacement.c b/tests/replacement.c index 3e762b0..6e5ece7 100644 --- a/tests/replacement.c +++ b/tests/replacement.c @@ -40,7 +40,7 @@ main(int argc, char **argv) uint32_t hash_str1 = fnv1_hash_string(str1); struct hash_entry *entry; - ht = hash_table_create(fnv1_hash_string, string_key_equals); + ht = hash_table_create_for_string(); hash_table_insert_pre_hashed(ht, hash_str1, str1, str1); hash_table_insert(ht, str2, str2); diff --git a/tests/set/destroy_callback.c b/tests/set/destroy_callback.c index fd76bb9..df600c0 100644 --- a/tests/set/destroy_callback.c +++ b/tests/set/destroy_callback.c @@ -53,7 +53,7 @@ main(int argc, char **argv) struct set *set; uint32_t hash_str1 = fnv1_hash_string(str1); - set = set_create(fnv1_hash_string, string_key_equals); + set = set_create_for_string(); set_add_pre_hashed(set, hash_str1, str1); set_add(set, str2); diff --git a/tests/set/insert_and_lookup.c b/tests/set/insert_and_lookup.c index d1c426e..665cd93 100644 --- a/tests/set/insert_and_lookup.c +++ b/tests/set/insert_and_lookup.c @@ -40,7 +40,7 @@ main(int argc, char **argv) uint32_t hash_str1 = fnv1_hash_string(str1); struct set_entry *entry; - set = set_create(fnv1_hash_string, string_key_equals); + set = set_create_for_string(); set_add_pre_hashed(set, hash_str1, str1); set_add(set, str2); diff --git a/tests/set/null_remove.c b/tests/set/null_remove.c index 853698d..9557887 100644 --- a/tests/set/null_remove.c +++ b/tests/set/null_remove.c @@ -36,7 +36,7 @@ main(int argc, char **argv) { struct set *set; - set = set_create(fnv1_hash_string, string_key_equals); + set = set_create_for_string(); set_remove_entry(set, NULL); diff --git a/tests/set/replacement.c b/tests/set/replacement.c index bdf304f..89a87ee 100644 --- a/tests/set/replacement.c +++ b/tests/set/replacement.c @@ -40,7 +40,7 @@ main(int argc, char **argv) uint32_t hash_str1 = fnv1_hash_string(str1); struct set_entry *entry; - set = set_create(fnv1_hash_string, string_key_equals); + set = set_create_for_string(); set_add_pre_hashed(set, hash_str1, str1); set_add(set, str2); |