Created
December 3, 2009 20:37
-
-
Save ericentin/248493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stddef.h> | |
#include "gdsl.h" | |
typedef struct _Block { | |
// Important key member | |
int key; | |
// Rest of the stuff... | |
int foo, bar, baz; | |
const char * name; | |
} Block; | |
const char *my_key(void *val) { | |
return (const char *)&(((Block *)val)->key); | |
} | |
ulong my_hash(const char *val) { | |
return (ulong)(*((int *)val)); | |
} | |
void print_block(Block *b){ | |
printf("Block named: %s, key: %d, foo, bar, baz: %d, %d, %d\n", b->name, b->key, b->foo, b->bar, b->baz); | |
} | |
int main() { | |
gdsl_hash_t hash = gdsl_hash_alloc("hash", | |
NULL, | |
NULL, | |
my_key, | |
my_hash, | |
2); | |
Block a = {0, 1, 2, 3, "Hi"}, b = {1, 1, 2, 3, "Sup."}; | |
gdsl_hash_insert(hash, &a); | |
gdsl_hash_insert(hash, &b); | |
print_block(gdsl_hash_search(hash, (char *)&(a.key))); | |
print_block(gdsl_hash_search(hash, (char *)&(b.key))); | |
gdsl_hash_free(hash); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment