/* * A unit test and example of how to use the simple C hashmap */ #include #include #include #include "hashmap.h" #define KEY_MAX_LENGTH (256) #define KEY_PREFIX ("somekey") #define KEY_COUNT (1024*1024) typedef struct data_struct_s { char key_string[KEY_MAX_LENGTH]; int number; } data_struct_t; int main(char* argv, int argc) { int index; int error; map_t mymap; char key_string[KEY_MAX_LENGTH]; data_struct_t* value; mymap = hashmap_new(); /* First, populate the hash map with ascending values */ for (index=0; indexkey_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, index); value->number = index; error = hashmap_put(mymap, value->key_string, value); assert(error==MAP_OK); } /* Now, check all of the expected values are there */ for (index=0; indexnumber==index); } /* Make sure that a value that wasn't in the map can't be found */ snprintf(key_string, KEY_MAX_LENGTH, "%s%d", KEY_PREFIX, KEY_COUNT); error = hashmap_get(mymap, key_string, (void**)(&value)); /* Make sure the value was not found */ assert(error==MAP_MISSING); /* Free all of the values we allocated and remove them from the map */ for (index=0; index