mirror of
https://github.com/bkthomps/Containers.git
synced 2025-12-29 02:20:58 +00:00
Make c89 compatible (#27)
This commit is contained in:
@@ -12,8 +12,8 @@ static int hash_count;
|
||||
|
||||
static unsigned long hash_int(const void *const key)
|
||||
{
|
||||
hash_count++;
|
||||
unsigned long hash = 17;
|
||||
hash_count++;
|
||||
hash = 31 * hash + *(int *) key;
|
||||
return hash;
|
||||
}
|
||||
@@ -25,16 +25,22 @@ static unsigned long bad_hash_int(const void *const key)
|
||||
|
||||
void test_unordered_map(void)
|
||||
{
|
||||
int val_arr[10] = {5, 9, 4, -5, 0, 6, 1, 5, 7, 2};
|
||||
unordered_map me;
|
||||
int key;
|
||||
int num;
|
||||
int value;
|
||||
int i;
|
||||
int j;
|
||||
assert(!unordered_map_init(0, sizeof(int), hash_int, compare_int));
|
||||
assert(!unordered_map_init(sizeof(int), 0, hash_int, compare_int));
|
||||
assert(!unordered_map_init(sizeof(int), sizeof(int), NULL, compare_int));
|
||||
assert(!unordered_map_init(sizeof(int), sizeof(int), hash_int, NULL));
|
||||
unordered_map me = unordered_map_init(sizeof(int), sizeof(int),
|
||||
hash_int, compare_int);
|
||||
me = unordered_map_init(sizeof(int), sizeof(int), hash_int, compare_int);
|
||||
assert(unordered_map_size(me) == 0);
|
||||
assert(unordered_map_is_empty(me));
|
||||
int key = 4;
|
||||
int value = 9;
|
||||
key = 4;
|
||||
value = 9;
|
||||
unordered_map_put(me, &key, &value);
|
||||
assert(unordered_map_size(me) == 1);
|
||||
value = 5;
|
||||
@@ -50,8 +56,6 @@ void test_unordered_map(void)
|
||||
unordered_map_put(me, &key, &value);
|
||||
assert(unordered_map_size(me) == 2);
|
||||
assert(unordered_map_contains(me, &key));
|
||||
int val_arr[10] = {5, 9, 4, -5, 0, 6, 1, 5, 7, 2};
|
||||
int i;
|
||||
for (i = 0; i < 10; i++) {
|
||||
unordered_map_put(me, &val_arr[i], &value);
|
||||
assert(unordered_map_contains(me, &val_arr[i]));
|
||||
@@ -60,17 +64,16 @@ void test_unordered_map(void)
|
||||
for (i = 0; i < 10; i++) {
|
||||
assert(unordered_map_contains(me, &val_arr[i]));
|
||||
}
|
||||
int j;
|
||||
for (i = -100; i < 100; i++) {
|
||||
bool contains = false;
|
||||
int contains = 0;
|
||||
for (j = 0; j < 10; j++) {
|
||||
if (val_arr[j] == i) {
|
||||
contains = true;
|
||||
contains = 1;
|
||||
}
|
||||
}
|
||||
assert(unordered_map_contains(me, &i) == contains);
|
||||
}
|
||||
int num = -3;
|
||||
num = -3;
|
||||
assert(!unordered_map_remove(me, &num));
|
||||
assert(unordered_map_size(me) == 9);
|
||||
assert(!unordered_map_contains(me, &num));
|
||||
@@ -110,7 +113,7 @@ void test_unordered_map(void)
|
||||
assert(unordered_map_remove(me, &num));
|
||||
assert(unordered_map_size(me) == 0);
|
||||
assert(!unordered_map_contains(me, &num));
|
||||
// Add a lot of items and remove individually.
|
||||
/* Add a lot of items and remove individually. */
|
||||
for (i = 5000; i < 6000; i++) {
|
||||
unordered_map_put(me, &i, &value);
|
||||
assert(unordered_map_contains(me, &i));
|
||||
@@ -125,7 +128,7 @@ void test_unordered_map(void)
|
||||
unordered_map_clear(me);
|
||||
assert(unordered_map_size(me) == 0);
|
||||
assert(unordered_map_is_empty(me));
|
||||
// Add a lot of items and clear.
|
||||
/* Add a lot of items and clear. */
|
||||
for (i = 5000; i < 6000; i++) {
|
||||
unordered_map_put(me, &i, &value);
|
||||
assert(unordered_map_contains(me, &i));
|
||||
|
||||
Reference in New Issue
Block a user