From d89972c621524aac643c485fefa39ad3e6d3b6dc Mon Sep 17 00:00:00 2001 From: Leonardo Date: Sat, 4 May 2019 00:06:27 -0300 Subject: [PATCH] Fixing hashset and hashmap error with a pointer data type and adding a test to address that --- .travis.yml | 3 ++- src/hashmap.h | 6 ++++-- src/hashset.h | 6 ++++-- tests/pointertype.c | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 tests/pointertype.c diff --git a/.travis.yml b/.travis.yml index f7fa71f..1259e20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,5 @@ script: - ./iterators - gcc contains.c -Wall -Wextra -o contains -std=c11 - ./contains - + - gcc pointertype.c -Wall -Wextra -o pointertype -std=c11 + - ./pointertype diff --git a/src/hashmap.h b/src/hashmap.h index 9ff0b48..4a3b41a 100644 --- a/src/hashmap.h +++ b/src/hashmap.h @@ -295,7 +295,8 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531, return false; \ \ SNAME##_iter iter; \ - K result_key, max_key; \ + K result_key; \ + K max_key; \ V result_value; \ size_t index; \ \ @@ -326,7 +327,8 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531, return false; \ \ SNAME##_iter iter; \ - K result_key, min_key; \ + K result_key; \ + K min_key; \ V result_value; \ size_t index; \ \ diff --git a/src/hashset.h b/src/hashset.h index 65809cd..bc8159d 100644 --- a/src/hashset.h +++ b/src/hashset.h @@ -289,7 +289,8 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531, if (PFX##_empty(_set_)) \ return 0; \ \ - V result, max; \ + V result; \ + V max; \ size_t index; \ SNAME##_iter iter; \ \ @@ -311,7 +312,8 @@ static const size_t cmc_hashtable_primes[] = {53, 97, 191, 383, 769, 1531, if (PFX##_empty(_set_)) \ return 0; \ \ - V result, min; \ + V result; \ + V min; \ size_t index; \ SNAME##_iter iter; \ \ diff --git a/tests/pointertype.c b/tests/pointertype.c new file mode 100644 index 0000000..af320dc --- /dev/null +++ b/tests/pointertype.c @@ -0,0 +1,24 @@ +// Tests all containers if they accept a pinter type +// Compile with -Wall -Wextra +#include "../src/macro_collections.h" +#include + +COLLECTION_GENERATE(LIST, PUBLIC, l, list, /* FMOD */, /* K */, char *) +COLLECTION_GENERATE(STACK, PUBLIC, s, stack, /* FMOD */, /* K */, char *) +COLLECTION_GENERATE(QUEUE, PUBLIC, q, queue, /* FMOD */, /* K */, char *) +COLLECTION_GENERATE(DEQUE, PUBLIC, d, deque, /* FMOD */, /* K */, char *) +COLLECTION_GENERATE(LINKEDLIST, PUBLIC, ll, linked, /* FMOD */, /* K */, char *) +COLLECTION_GENERATE(HEAP, PUBLIC, h, heap, /* FMOD */, /* K */, char *) +COLLECTION_GENERATE(TREESET, PUBLIC, ts, tset, /* FMOD */, /* K */, char *) +COLLECTION_GENERATE(TREEMAP, PUBLIC, tm, tmap, /* FMOD */, char *, char *) +COLLECTION_GENERATE(HASHSET, PUBLIC, hs, hset, /* FMOD */, /* K */, char *) +COLLECTION_GENERATE(HASHMAP, PUBLIC, hm, hmap, /* FMOD */, char *, char *) + +int main(void) +{ + printf("+--------------------------------------------------+\n"); + printf("| Pointer Data Type is Working |\n"); + printf("+--------------------------------------------------+\n"); + + return 0; +}