X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drl%2Futil.h;fp=drl%2Futil.h;h=ffe3321814faa2542a6ec9b86942664527ab9061;hb=0be9704d6b24d09ebd55beedec52758cb88c570b;hp=0000000000000000000000000000000000000000;hpb=6747e89080a8265aa73320bd9f40a0fa6e1c161e;p=distributedratelimiting.git diff --git a/drl/util.h b/drl/util.h new file mode 100644 index 0000000..ffe3321 --- /dev/null +++ b/drl/util.h @@ -0,0 +1,63 @@ +/* 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); + +/* sundry items */ +void print_system_error(int ret); + + +#endif