diff options
author | Eric Anholt <eric@anholt.net> | 2009-11-23 11:59:37 +0100 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2009-11-23 18:05:51 -0800 |
commit | 773c0c87c10e8a12c67b42506d4fdd5241f08d6a (patch) | |
tree | f64a51ba0c0f5f3384119275c6f02f9b2b333b03 /tests | |
parent | bddf2a8aa9c47d47975ed0967a2d110530eb1444 (diff) |
New test for expanding the hash table and not losing entries.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/insert_many.c | 76 |
3 files changed, 81 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..be475a3 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,4 @@ +delete_and_lookup +insert_and_lookup +insert_many +null_destroy diff --git a/tests/Makefile.am b/tests/Makefile.am index 55a3d20..3e6aaad 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,6 +24,7 @@ LDADD = ../libhash_table.la TESTS = \ delete_and_lookup \ insert_and_lookup \ + insert_many \ null_destroy \ $() diff --git a/tests/insert_many.c b/tests/insert_many.c new file mode 100644 index 0000000..ef54e02 --- /dev/null +++ b/tests/insert_many.c @@ -0,0 +1,76 @@ +/* + * Copyright © 2009 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors: + * Eric Anholt <eric@anholt.net> + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> +#include "hash_table.h" +#include "fnv_hash.h" + +static uint32_t +uint32_t_key_hash(const void *key) +{ + /* Note that we're using the address of the key instead of the + * perfectly-hashed 32-bit value in the key, in order to trigger + * collisions. + */ + return (uint32_t)(uintptr_t)key; +} + +static int +uint32_t_key_equals(const void *a, const void *b) +{ + return *(uint32_t *)a == *(uint32_t *)b; +} + +int +main(int argc, char **argv) +{ + struct hash_table *ht; + struct hash_entry *entry; + int size = 10000; + uint32_t keys[size]; + uint32_t i; + + ht = hash_table_create(uint32_t_key_hash, uint32_t_key_equals); + + for (i = 0; i < size; i++) { + keys[i] = i; + + hash_table_insert(ht, keys + i, NULL); + } + + for (i = 0; i < size; i++) { + entry = hash_table_search(ht, keys + i); + assert(entry); + assert(*(uint32_t *)entry->key == i); + } + + hash_table_destroy(NULL, NULL); + + return 0; +} |