emu_hashtable.h File Reference

#include <stdint.h>
#include <emu/emu_list.h>
Include dependency graph for emu_hashtable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  emu_hashtable_item
struct  emu_hashtable_bucket_item
struct  emu_hashtable_bucket
struct  emu_hashtable

Typedefs

typedef bool(* emu_hashtable_cmp_cb )(void *a, void *b)
typedef uint32_t(* emu_hashtable_hash_cb )(void *key)
typedef void(* emu_hashtable_destructor )(void *data)

Functions

 header_list_typedefs (emu_hashtable_bucket_item_root, emu_hashtable_bucket_item, emu_hashtable_bucket_link)
 header_list_functions (emu_hashtable_bucket_items, emu_hashtable_bucket_item_root, emu_hashtable_bucket_item, link)
struct emu_hashtable_bucket_itememu_hashtable_bucket_item_new (void *key, void *value)
void emu_hashtable_bucket_item_free (struct emu_hashtable_bucket_item *ehbi)
struct emu_hashtable_bucketemu_hashtable_bucket_new (void)
void emu_hashtable_bucket_free (struct emu_hashtable_bucket *ehb)
void emu_hashtable_bucket_item_add (struct emu_hashtable_bucket *ehb, struct emu_hashtable_bucket_item *ehbi)
struct emu_hashtableemu_hashtable_new (uint32_t size, emu_hashtable_hash_cb hash, emu_hashtable_cmp_cb cmp)
void emu_hashtable_free (struct emu_hashtable *eh)
struct emu_hashtable_itememu_hashtable_search (struct emu_hashtable *eh, void *key)
struct emu_hashtable_itememu_hashtable_insert (struct emu_hashtable *eh, void *key, void *data)
bool emu_hashtable_delete (struct emu_hashtable *eh, void *key)
uint32_t emu_hashtable_string_hash (void *data)
bool emu_hashtable_string_cmp (void *a, void *b)
uint32_t emu_hashtable_ptr_hash (void *data)
bool emu_hashtable_ptr_cmp (void *a, void *b)

Typedef Documentation

typedef bool(* emu_hashtable_cmp_cb)(void *a, void *b)
typedef void(* emu_hashtable_destructor)(void *data)
typedef uint32_t(* emu_hashtable_hash_cb)(void *key)

Function Documentation

void emu_hashtable_bucket_free ( struct emu_hashtable_bucket ehb  ) 
void emu_hashtable_bucket_item_add ( struct emu_hashtable_bucket ehb,
struct emu_hashtable_bucket_item ehbi 
)
void emu_hashtable_bucket_item_free ( struct emu_hashtable_bucket_item ehbi  ) 

Referenced by emu_hashtable_free().

struct emu_hashtable_bucket_item* emu_hashtable_bucket_item_new ( void *  key,
void *  value 
) [read]
struct emu_hashtable_bucket* emu_hashtable_bucket_new ( void   )  [read]
bool emu_hashtable_delete ( struct emu_hashtable eh,
void *  key 
)

delete a key/data pair from the hashtable

Parameters:
eh the hashtable
key the key to the key/data pair to remove
Returns:
on success: true on failure: false

References emu_hashtable::buckets, emu_hashtable::cmp, emu_hashtable::hash, emu_hashtable_bucket_item::item, emu_hashtable_bucket::items, emu_hashtable_item::key, emu_hashtable::key_destructor, emu_hashtable::size, emu_hashtable_item::value, and emu_hashtable::value_destructor.

void emu_hashtable_free ( struct emu_hashtable eh  ) 

Free the hashtable, if the emu_hashtable_destructors key_/value_destructor within the emu_hashtable are set, freeing the hashtable will free the data too, if not, only the hashtable itself is free'd.

Parameters:
eh the hashtable

References emu_hashtable::buckets, emu_hashtable_bucket_free(), emu_hashtable_bucket_item_free(), emu_hashtable_bucket_item::item, emu_hashtable_bucket::items, emu_hashtable_item::key, emu_hashtable::key_destructor, emu_hashtable::size, emu_hashtable_item::value, and emu_hashtable::value_destructor.

Referenced by emu_env_linux_free(), emu_env_w32_dll_free(), emu_shellcode_test(), and emu_track_and_source_free().

Here is the call graph for this function:

struct emu_hashtable_item* emu_hashtable_insert ( struct emu_hashtable eh,
void *  key,
void *  data 
) [read]

Insert a key/data pair into the hashtable

Parameters:
eh the hashtable
key the key
data the data
Returns:
on success: pointer to the emu_hashtable_item on failure: NULL

References emu_hashtable::buckets, emu_hashtable_bucket_item_new(), emu_hashtable_bucket_new(), emu_hashtable_search(), emu_hashtable::hash, emu_hashtable_bucket_item::item, emu_hashtable_bucket::items, emu_hashtable::size, and emu_hashtable_item::value.

Referenced by emu_env_linux_new(), emu_env_w32_dll_exports_copy(), emu_shellcode_run_and_track(), and emu_source_instruction_graph_create().

Here is the call graph for this function:

struct emu_hashtable* emu_hashtable_new ( uint32_t  size,
emu_hashtable_hash_cb  hash,
emu_hashtable_cmp_cb  cmp 
) [read]

Create a bucket hashtable Due to the problems of double hashing when it comes to deleting elements we choose bucket hashtables. If used wrong, as slow als linked lists, if used right, as fast as a real (doublehash) hashtable.

Parameters:
size the size
hash pointer to the hash function
cmp pointer to the compare function
Returns:
on success, pointer to the hashtable on failure, NULL

References emu_hashtable::buckets, emu_hashtable::cmp, emu_hashtable::hash, and emu_hashtable::size.

Referenced by emu_env_linux_new(), emu_env_w32_dll_exports_copy(), emu_shellcode_test(), and emu_source_instruction_graph_create().

bool emu_hashtable_ptr_cmp ( void *  a,
void *  b 
)
uint32_t emu_hashtable_ptr_hash ( void *  data  ) 
struct emu_hashtable_item* emu_hashtable_search ( struct emu_hashtable eh,
void *  key 
) [read]
bool emu_hashtable_string_cmp ( void *  a,
void *  b 
)
uint32_t emu_hashtable_string_hash ( void *  key  ) 

string hashing function to avoid duplicate code algo is djb2 taken from http://www.cse.yorku.ca/~oz/hash.html

Parameters:
data the string to hash
Returns:
the hash

Referenced by emu_env_linux_new(), and emu_env_w32_dll_exports_copy().

header_list_functions ( emu_hashtable_bucket_items  ,
emu_hashtable_bucket_item_root  ,
emu_hashtable_bucket_item  ,
link   
)
header_list_typedefs ( emu_hashtable_bucket_item_root  ,
emu_hashtable_bucket_item  ,
emu_hashtable_bucket_link   
)

Generated on Sun Jan 9 16:48:08 2011 for libemu by  doxygen 1.6.1