/** \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; /** 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; /**