simple_hashtable/usage_example.c

27 lines
709 B
C

#include "shash.h"
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
// Initialize an empty hashtable
shash_hashtable_t hashtable;
if (shash_init_hashtable(&hashtable, 100) == -1)
return EXIT_FAILURE;
// Store some data
if (
shash_set("FOO", 3, "Hello", &hashtable) == EXIT_FAILURE ||
shash_set("BAR", 3, "World!", &hashtable) == EXIT_FAILURE)
return EXIT_FAILURE;
// And retrieve it
char *retrieved_foo = shash_get("FOO", 3, &hashtable);
char *retrieved_bar = shash_get("BAR", 3, &hashtable);
printf("%s, %s\n", retrieved_foo, retrieved_bar);
// Destroy the hashtable
shash_destroy_hashtable(&hashtable);
return 0;
}