feat(queue): introduce a queue ds, internally this is just a stack...

the only actual difference is a oneline change which makes pushing
append instead of prepend the new data.
This commit is contained in:
Squibid 2025-11-17 17:51:57 -05:00
parent 9daffd4ed1
commit 758edf9d30
Signed by: squibid
GPG key ID: BECE5684D3C4005D
4 changed files with 93 additions and 1 deletions

35
ds.h
View file

@ -27,6 +27,8 @@ typedef struct {
ds_sll_t *items;
} ds_stack_t;
typedef ds_stack_t ds_queue_t;
#define ds_ll_foreach(t, ll) for (t *cur = ll; cur; cur = cur->next)
/**
@ -206,4 +208,37 @@ void *ds_stack_pop(ds_stack_t *stack);
*/
void *ds_stack_peek(ds_stack_t *stack, unsigned x);
/**
* @brief initialize a new queue
*
* @return the queue
*/
ds_queue_t *ds_queue_init(void);
/**
* @brief push new data onto the queue
*
* @param queue the queue
* @param data the data
* @return 0 on success
*/
int ds_queue_push(ds_queue_t *queue, void *data);
/**
* @brief pop the data off the top of the queue
*
* @param queue the queue
* @return the data
*/
void *ds_queue_pop(ds_queue_t *queue);
/**
* @brief peek forward x items
*
* @param queue the queue
* @param x how many items to look ahead
* @return the data or NULL if out of range
*/
void *ds_queue_peek(ds_queue_t *queue, unsigned x);
#endif