[view source]
long cp_hash_char(void *key);
int cp_hash_compare_char(void *a, void *b);
long cp_hash_int(void *key);
int cp_hash_compare_int(void *a, void *b);
long cp_hash_long(void *key);
int cp_hash_compare_long(void *a, void *b);
long cp_hash_float(void *key);
int cp_hash_compare_float(void *a, void *b);
long cp_hash_double(void *key);
int cp_hash_compare_double(void *a, void *b);
long cp_hash_addr(void *key);
int cp_hash_compare_addr(void *a, void *b);
long cp_hash_string(void *key);
int cp_hash_compare_string(void *a, void *b);
long cp_hash_istring(void *key);
int cp_hash_compare_istring(void *a, void *b);
#include <stdio.h> #include <string.h> /* for strdup */ #include <strings.h> /* for strcasecmp */ #include <stdlib.h> /* for free */ #include <cprops/hashtable.h> int main() { cp_hashtable *t = cp_hashtable_create_by_option(COLLECTION_MODE_NOSYNC | COLLECTION_MODE_COPY | COLLECTION_MODE_DEEP, 10, cp_hash_istring, (cp_compare_fn) strcasecmp, (cp_copy_fn) strdup, (cp_destructor_fn) free, (cp_copy_fn) strdup, (cp_destructor_fn) free); cp_hashtable_put(t, "ed", "123"); cp_hashtable_put(t, "zed", "345"); cp_hashtable_put(t, "fred", "789"); while (1) { char name[80]; char *number; printf("enter name [quit]: "); name[0] = '\0'; fgets(name, 80, stdin); name[strlen(name) - 1] = '\0'; /* chop newline */ if (name[0] == '\0') break; if ((number = cp_hashtable_get(t, name)) != NULL) printf("%s: %s\n", name, number); else printf("no entry for %s\n", name); } cp_hashtable_destroy(t); return 0; }
for notes on compiling and linking see cprops(3).
This document was created by
man2html,
using the manual pages. Time: 12:01:45 GMT, May 23, 2006 |