From 1fa53c5bf8d0717f784c79abaa5111f88ab00221 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Wed, 15 Sep 2021 17:04:21 +0200 Subject: Squashed 'dependencies/uthash/' changes from 8e67ced..bf15263 bf15263 Fix a "bug" in the example where option 3 interfered with option 1's counter. b6e24ef Use `malloc(sizeof *s)` in example code. a109c6b Stop using `gets` in example.c. c85c9e1 fix: fix utstack example's compiling error 86e6776 Replace *.github.com urls with *.github.io (#227) e493aa9 Bump version to 2.3.0. ae2ac52 Fix README.md to display the *actual* TravisCI status. 134e241 Silence -Wswitch-default warnings, and add it to the TravisCI config. 62fefa6 Fix some typos in userguide.txt, and re-remove spaces in macro definitions. 37d2021 tests: add whitespaces to example code 524ca1a doc: add whitespaces to documentation 0f6c619 Fix a typo in the documentation for HASH_COUNT. NFC. 388134a Rename uthash_memcmp to HASH_KEYCMP, step 3. 053bed1 Eliminate HASH_FCN; change the handling of HASH_FUNCTION to match HASH_KEYCMP. f0e1bd9 Refactor test93.c to avoid scan-build warnings. 45af88c Remove two dead writes in tests, to silence scan-build warnings. 66e2668 Bump version to 2.2.0. 973bd67 uthash.h: Swap multiplicands to put the widest ones first. 15ad042 Always include , unless HASH_NO_STDINT is defined by the user. 6b4768b Rename uthash_memcmp to HASH_KEYCMP, step 2. e64c7f0 Update tests/README to describe the most recently added tests. NFC. c62796c HASH_CLEAR after some tests, to eliminate "memory leak" warnings. 7f0aadb Support spaces in $exe path 0831d9a uthash.h: fix compiler warning -Wcast-qual ba2fbfd utarray.h: preserve constness in utarray_str_cpy git-subtree-dir: dependencies/uthash git-subtree-split: bf15263081be6229be31addd48566df93921cb46 --- tests/test96.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/test96.c (limited to 'tests/test96.c') diff --git a/tests/test96.c b/tests/test96.c new file mode 100644 index 000000000..700bdcf30 --- /dev/null +++ b/tests/test96.c @@ -0,0 +1,48 @@ +#include +#include + +#define HASH_FUNCTION(a,n,hv) (hv = clockface_hash(*(const int*)(a))) +#define HASH_KEYCMP(a,b,n) clockface_neq(*(const int*)(a), *(const int*)(b)) + +#include "uthash.h" + +struct clockface { + int time; + UT_hash_handle hh; +}; + +int clockface_hash(int time) +{ + return (time % 4); +} + +int clockface_neq(int t1, int t2) +{ + return ((t1 % 12) != (t2 % 12)); +} + +int main() +{ + int random_data[] = { + 56, 7, 10, 39, 82, 15, 31, 26, 51, 83, + 46, 92, 49, 25, 80, 54, 97, 9, 34, 86, + 87, 28, 13, 91, 95, 63, 71, 100, 44, 42, + 16, 32, 6, 85, 40, 20, 18, 99, 22, 1 + }; + + struct clockface *times = NULL; + for (int i=0; i < 40; ++i) { + struct clockface *elt = (struct clockface *)malloc(sizeof(*elt)); + struct clockface *found = NULL; + elt->time = random_data[i]; + HASH_FIND_INT(times, &elt->time, found); + if (found) { + printf("time %d found with value %d\n", elt->time, found->time); + } else { + printf("time %d not found, inserting it\n", elt->time); + HASH_ADD_INT(times, time, elt); + } + } + + return 0; +} -- cgit v1.2.3