/** \file util.h Generic utilities library. */ #ifndef FISH_UTIL_H #define FISH_UTIL_H #include #include /** Data structure for an automatically resizing dynamically allocated queue, */ typedef struct dyn_queue { /** Start of the array */ void **start; /** End of the array*/ void **stop; /** Where to insert elements */ void **put_pos; /** Where to remove elements */ void **get_pos; } dyn_queue_t; /** Internal struct used by hash_table_t. */ typedef struct { /** Hash key*/ const void *key; /** Value */ const void *data; } hash_struct_t; /** Data structure for the hash table implementaion. A hash table allows for retrieval and removal of any element in O(1), so long as a proper hash function is supplied. The hash table is implemented using a single hash function and element storage directly in the array. When a collision occurs, the hashtable iterates until a zero element is found. When the table is 75% full, it will automatically reallocate itself. This reallocation takes O(n) time. The table is guaranteed to never be more than 75% full or less than 30% full (Unless the table is nearly empty). Its size is always a Mersenne number. */ typedef struct hash_table { /** The array containing the data */ hash_struct_t *arr; /** Number of elements */ int count; /** Length of array */ int size; /** Hash function */ int (*hash_func)( const void *key ); /** Comparison function */ int (*compare_func)( const void *key1, const void *key2 ); } hash_table_t; /** Data structure for an automatically resizing dynamically allocated priority queue. A priority queue allows quick retrieval of the smallest element of a set (This implementation uses O(log n) time). This implementation uses a heap for storing the queue. */ typedef struct priority_queue { /** Array contining the data */ void **arr; /** Number of elements*/ int count; /** Length of array */ int size; /** Comparison function */ int (*compare)(void *e1, void *e2); } priority_queue_t; /** Array list struct. A dynamically growing list that supports stack operations. */ typedef struct array_list { /** Array containing the data */ const void **arr; /** Position to append elements at*/ int pos; /** Length of array */ int size; } array_list_t; /** Linked list node. */ typedef struct _ll_node { /** Next node */ struct _ll_node *next, /** Previous node */ *prev; /** Node data */ void *data; } ll_node_t; /** Buffer for concatenating arbitrary data. */ typedef struct buffer { char *buff; /**