/* See the DRL-LICENSE file for this file's software license. */ #ifndef _UTIL_H_ #define _UTIL_H_ #define _XOPEN_SOURCE 600 /* for pthread_rwlock_t */ /* * Jenkins hash support */ typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; #include #define MAP_KEY_SIZE 4 /* all 4 bytes for now */ #define GENERIC_HASH_SIZE 16 /* must be powers of 2 */ enum bool {false=0,true}; struct map{ struct map_entry *table[GENERIC_HASH_SIZE]; int iterator_row; struct map_entry *iterator; int size; }; struct map_entry { struct map_entry *nxt; char *key; void *value; }; /* typedef's */ typedef struct map *map_handle; /* function prototypes */ char* get_local_ip(); void ip_from_bytes(uint32_t addr, char *buf); uint32_t myrand(); int myrand_boolean(); double myrand_double(); int my_lg(int x); /* hash map interface */ void init_hashing(void); map_handle allocate_map(void); void free_map(map_handle map, int dealloc); void** map_to_array(map_handle map, int *length); void* map_search(map_handle map,void *key, int keylen); void map_reset_iterate(map_handle map); void* map_next(map_handle table); void* map_remove(map_handle map,void *key, int keylen); void map_insert(map_handle map, void *key, int keylen, void *value); int map_size(map_handle map); #endif