1 /* 2 Copyright (c) 1998--2006 Benhur Stein 3 4 This file is part of Paj�. 5 6 Paj� is free software; you can redistribute it and/or modify it under 7 the terms of the GNU Lesser General Public License as published by the 8 Free Software Foundation; either version 2 of the License, or (at your 9 option) any later version. 10 11 Paj� is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 14 for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with Paj�; if not, write to the Free Software Foundation, Inc., 18 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. 19 */ 20 21 22 ////////////////////////////////////////////////// 23 /* Author: Geovani Ricardo Wiedenhoft */ 24 /* Email: grw@inf.ufsm.br */ 25 ////////////////////////////////////////////////// 26 27 28 #ifndef _HASH_H_ 29 #define _HASH_H_ 30 31 #define MAX_HASH 100 32 33 typedef void* hash_data_t; 34 35 typedef void* hash_key_t; 36 37 typedef struct hash_element_t_{ 38 hash_key_t key; 39 hash_data_t data; 40 struct hash_element_t_ *next; 41 }hash_element_t; 42 43 typedef int(*hash_func_t)(hash_key_t); 44 typedef void(*hash_func_copy_t)(hash_element_t*, hash_key_t, hash_data_t); 45 typedef bool(*hash_func_compare_t)(hash_key_t, hash_key_t); 46 typedef void(*hash_func_destroy_t)(hash_element_t*); 47 48 typedef struct { 49 hash_element_t hash[MAX_HASH]; 50 hash_func_t hash_func; 51 hash_func_copy_t hash_copy; 52 hash_func_compare_t hash_compare; 53 hash_func_destroy_t hash_destroy; 54 }hash_t; 55 56 int hash_value(hash_key_t key); 57 int hash_value_string(hash_key_t key); 58 int hash_value_int(hash_key_t key); 59 void hash_null(void *p); 60 void hash_initialize(hash_t *h, hash_func_t func, hash_func_copy_t copy, hash_func_compare_t compare, hash_func_destroy_t destroy); 61 void hash_finalize(hash_t *h); 62 void hash_destroy(hash_element_t *element); 63 void hash_destroy_string(hash_element_t *element); 64 void hash_destroy_int(hash_element_t *element); 65 bool hash_key_cmp(hash_key_t key, hash_key_t key2); 66 bool hash_key_cmp_string(hash_key_t key, hash_key_t key2); 67 bool hash_key_cmp_int(hash_key_t key, hash_key_t key2); 68 void hash_copy (hash_element_t *element, hash_key_t key, hash_data_t data); 69 void hash_copy_string (hash_element_t *element, hash_key_t key, hash_data_t data); 70 void hash_copy_int (hash_element_t *element, hash_key_t key, hash_data_t data); 71 hash_data_t *hash_locate(hash_t *h, hash_key_t key); 72 bool hash_find(hash_t *h, hash_key_t key); 73 void hash_insert(hash_t *h, hash_key_t key, hash_data_t data); 74 void hash_remove(hash_t *h, hash_key_t key); 75 76 77 #endif /*_HASH_H_*/ 78