/** \file util.h Generic utilities library. All containers in this library except strinb_buffer_t are written so that they don't allocate any memory until the first element is inserted into them. That way it is known to be very cheap to initialize various containers at startup, supporting the fish notion of doing as much lazy initalization as possible. */ #ifndef FISH_UTIL_H #define FISH_UTIL_H #include #include #include /** Typedef for a generic function pointer */ typedef void (*func_ptr_t)(); /** A union of all types that can be stored in an array_list_t. This is used to make sure that the pointer type can fit whatever we want to insert. */ typedef union { /** long value */ long long_val; /** pointer value */ void *ptr_val; /** function pointer value */ func_ptr_t func_val; } anything_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 */ anything_t *arr; /** Internal cursor position of the array_list_t. This is the position to append elements at. This is also what the array_list_t considers to be its true size, as reported by al_get_count(), etc. Calls to e.g. al_insert will preserve the values of all elements up to pos. */ size_t pos; /** Amount of memory allocated in arr, expressed in number of elements. */ size_t 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; /**