00001 // Copyright (C) 2011 CNRS - Ecole Polytechnique - INRIA. 00002 // 00003 // This file is part of TIFA. 00004 // 00005 // TIFA is free software; you can redistribute it and/or modify it under the 00006 // terms of the GNU Lesser General Public License as published by the Free 00007 // Software Foundation; either version 2.1 of the License, or (at your option) 00008 // any later version. 00009 // 00010 // TIFA is distributed in the hope that it will be useful, but WITHOUT ANY 00011 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00013 // more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, 00017 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00030 #if !defined(_TIFA_HASHTABLE_H_) 00031 00035 #define _TIFA_HASHTABLE_H_ 00036 00037 #include <inttypes.h> 00038 #include "linked_list.h" 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00059 struct struct_hashtable_t { 00063 uint32_t alloced; 00067 uint32_t nentries; 00072 linked_list_t* buckets; 00083 int (*cmp_func) (const void* const key_a, const void* const key_b); 00095 uint32_t (*hash_func) (const void* const key); 00096 }; 00101 typedef struct struct_hashtable_t hashtable_t; 00102 00110 struct struct_hashtable_entry_t { 00114 void* key; 00118 void* data; 00119 }; 00124 typedef struct struct_hashtable_entry_t hashtable_entry_t; 00125 00140 hashtable_t* alloc_init_hashtable( 00141 uint32_t size, 00142 int (*cmp_func) (const void* const key_a, const void* const key_b), 00143 uint32_t (*hash_func) (const void* const key) 00144 ); 00145 00160 void free_hashtable(hashtable_t* htable); 00161 00177 void add_entry_in_hashtable(hashtable_t* const htable, 00178 const void* const key, const void* const data); 00191 void* get_entry_in_hashtable(hashtable_t* const htable, 00192 const void* const key); 00193 00212 void* remove_entry_in_hashtable(hashtable_t* const htable, 00213 const void* const key); 00214 00215 #ifdef __cplusplus 00216 } 00217 #endif 00218 00219 #endif