68 lines
1.7 KiB
C
68 lines
1.7 KiB
C
#include <hash.h>
|
||
|
||
#include <stdio.h>
|
||
#include <string.h>
|
||
#include <malloc.h>
|
||
|
||
#define MAX_CHANNUM 1024
|
||
|
||
u_int32_t hash_function(void *key, u_int32_t number_of_buckets)
|
||
{
|
||
// return hash_hash_int(key, number_of_buckets);
|
||
|
||
return hash_hash_string(key, number_of_buckets); // вызывается по-умолчанию, если hash_function=NULL в hash_initialise()
|
||
}
|
||
|
||
int compare_keys(void *key1, void *key2)
|
||
{
|
||
// return hash_compare_int(key1, key2);
|
||
|
||
return hash_compare_string(key1, key2); // вызывается по-умолчанию, если compare_keys=NULL в hash_initialise()
|
||
}
|
||
|
||
int duplicate_key(void **destination, void *source)
|
||
{
|
||
// hash_copy_int(destination, source);
|
||
|
||
hash_copy_string(destination, source); // вызывается по умолчанию, если duplicate_key=NULL в hash_initialise()
|
||
|
||
return 0;
|
||
}
|
||
|
||
void free_key(void *key)
|
||
{
|
||
void *warnings_stub = key;
|
||
warnings_stub = warnings_stub;
|
||
}
|
||
|
||
void free_value(void *value)
|
||
{
|
||
void *warnings_stub = value;
|
||
warnings_stub = warnings_stub;
|
||
}
|
||
|
||
int main()
|
||
{
|
||
u_int32_t nch = 5;
|
||
|
||
struct hash h;
|
||
|
||
//~ hash_initialise(&h, 2 * nch, NULL, NULL, NULL, NULL, NULL); // пример работы с ключом-строкой
|
||
|
||
hash_initialise(&h, 2 * nch, hash_function, compare_keys, duplicate_key, free_key, free_value);
|
||
|
||
hash_insert(&h, "Shashkin", "Kolan");
|
||
hash_insert(&h, "Iljin", "Egor");
|
||
hash_insert(&h, "Korsakov", "Kostya");
|
||
hash_insert(&h, "Sinelnikov", "Alexandr");
|
||
hash_insert(&h, "Kochetkov", "Sergey");
|
||
hash_insert(&h, "Bovykin", "Sergey");
|
||
hash_insert(&h, "Novikov", "Alexey");
|
||
|
||
char *val_ptr;
|
||
hash_retrieve(&h, "Kochetkov", (void **)&val_ptr);
|
||
printf("Kochetkov = %s\n", val_ptr);
|
||
hash_deinitialise(&h);
|
||
return 0;
|
||
}
|