emu_hashtable.h

Go to the documentation of this file.
00001 /********************************************************************************
00002  *                               libemu
00003  *
00004  *                    - x86 shellcode emulation -
00005  *
00006  *
00007  * Copyright (C) 2007  Paul Baecher & Markus Koetter
00008  * 
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License
00011  * as published by the Free Software Foundation; either version 2
00012  * of the License, or (at your option) any later version.
00013  * 
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00022  * 
00023  * 
00024  *             contact nepenthesdev@users.sourceforge.net  
00025  *
00026  *******************************************************************************/
00027 
00028 #ifndef EMU_HASHTABLE_H
00029 #define EMU_HASHTABLE_H
00030 
00031 
00032 #include <stdint.h>
00033 #include <emu/emu_list.h>
00034 
00041 struct emu_hashtable_item 
00042 {
00043         void *key;
00044         void *value;
00045 };
00046 
00047 
00048 typedef bool (*emu_hashtable_cmp_cb)(void *a, void *b);
00049 typedef uint32_t (*emu_hashtable_hash_cb)(void *key);
00050 typedef void (*emu_hashtable_destructor)(void *data);
00051 
00052 
00053 header_list_typedefs(emu_hashtable_bucket_item_root,emu_hashtable_bucket_item,emu_hashtable_bucket_link);
00054 
00055 struct emu_hashtable_bucket_item
00056 {
00057         struct emu_hashtable_item item;
00058         emu_hashtable_bucket_link link;
00059 };
00060 header_list_functions(emu_hashtable_bucket_items,emu_hashtable_bucket_item_root, emu_hashtable_bucket_item, link);
00061 
00062 struct emu_hashtable_bucket_item *emu_hashtable_bucket_item_new(void *key, void *value);
00063 void emu_hashtable_bucket_item_free(struct emu_hashtable_bucket_item *ehbi);
00064 
00065 struct emu_hashtable_bucket
00066 {
00067         emu_hashtable_bucket_item_root *items;
00068 };
00069 
00070 struct emu_hashtable_bucket *emu_hashtable_bucket_new(void);
00071 void emu_hashtable_bucket_free(struct emu_hashtable_bucket *ehb);
00072 void emu_hashtable_bucket_item_add(struct emu_hashtable_bucket *ehb, struct emu_hashtable_bucket_item *ehbi);
00073 
00074 
00084 struct emu_hashtable
00085 {
00086         uint32_t size;
00087         uint32_t filled;
00088         uint32_t item_count;
00089 
00090         struct emu_hashtable_bucket **buckets;
00091 
00092         emu_hashtable_hash_cb hash;
00093         emu_hashtable_cmp_cb cmp;
00094 
00095         emu_hashtable_destructor key_destructor;
00096         emu_hashtable_destructor value_destructor;
00097 };
00098 
00099 
00114 struct emu_hashtable *emu_hashtable_new(uint32_t size, 
00115                                                                                            emu_hashtable_hash_cb hash, 
00116                                                                                            emu_hashtable_cmp_cb cmp);
00117 
00126 void emu_hashtable_free(struct emu_hashtable *eh);
00127 
00128 
00138 struct emu_hashtable_item *emu_hashtable_search(struct emu_hashtable *eh, void *key);
00139 
00150 struct emu_hashtable_item *emu_hashtable_insert(struct emu_hashtable *eh, void *key, void *data);
00151 
00161 bool emu_hashtable_delete(struct emu_hashtable *eh, void *key);
00162 
00163 
00164 uint32_t emu_hashtable_string_hash(void *data);
00165 bool emu_hashtable_string_cmp(void *a, void *b);
00166 
00167 uint32_t emu_hashtable_ptr_hash(void *data);
00168 bool emu_hashtable_ptr_cmp(void *a, void *b);
00169 
00170 
00171 #endif // EMU_HASHTABLE_H

Generated on Sun Jan 9 16:47:44 2011 for libemu by  doxygen 1.6.1