2025-01-18 17:24:36 +03:00
|
|
|
#ifndef BH_QUEUE_H
|
|
|
|
|
#define BH_QUEUE_H
|
|
|
|
|
|
|
|
|
|
|
2025-02-02 21:40:31 +03:00
|
|
|
#include "Common.h"
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
2025-01-30 13:53:26 +03:00
|
|
|
typedef struct BH_Queue BH_Queue;
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-02-03 15:18:57 +03:00
|
|
|
* Creates the new queue.
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \return On success, returns the queue pointer.
|
2025-01-18 17:24:36 +03:00
|
|
|
* \return On failure, returns a null pointer.
|
|
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
BH_Queue *BH_QueueNew(void);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-02-03 15:18:57 +03:00
|
|
|
* Frees the \a queue.
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
2025-01-18 17:24:36 +03:00
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
void BH_QueueFree(BH_Queue *queue);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-02-03 15:18:57 +03:00
|
|
|
* Clears the \a queue.
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
2025-01-18 17:24:36 +03:00
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
void BH_QueueClear(BH_Queue *queue);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-02-03 15:18:57 +03:00
|
|
|
* Reserves the space for \a size amount of value in the \a queue.
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* This function can both expand and shrink the available space in queue.
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
|
|
|
|
* \param size Capacity
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
|
|
|
|
* \note Calling this function will invalidate iterators.
|
2025-02-03 15:18:57 +03:00
|
|
|
* \note Actual queue capacity can be bigger then requested.
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \return On success, returns zero.
|
2025-01-18 17:24:36 +03:00
|
|
|
* \return On failure, returns error code.
|
|
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
int BH_QueueReserve(BH_Queue *queue,
|
|
|
|
|
size_t size);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Inserts the \a value into the \a queue.
|
|
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
|
|
|
|
* \param value Value
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
|
|
|
|
* \note Calling this function will invalidate iterators.
|
|
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \return On success, returns zero.
|
2025-01-18 17:24:36 +03:00
|
|
|
* \return On failure, returns error code.
|
|
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
int BH_QueueInsert(BH_Queue *queue,
|
|
|
|
|
void *value);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes front value from the \a queue.
|
|
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
|
|
|
|
* \note Calling this function will invalidate iterators.
|
|
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
void BH_QueueRemove(BH_Queue *queue);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-02-03 15:18:57 +03:00
|
|
|
* Returns front \a value from the \a queue.
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
|
|
|
|
* \param value Value
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \return On success, returns zero.
|
|
|
|
|
* \return On failure, returns error code.
|
2025-01-18 17:24:36 +03:00
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
int BH_QueueFront(BH_Queue *queue,
|
|
|
|
|
void **value);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if the \a queue is empty.
|
|
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
|
|
|
|
* \return If queue is empty, returns non-zero value
|
2025-02-03 15:18:57 +03:00
|
|
|
* \return If queue is not empty, returns zero
|
2025-01-18 17:24:36 +03:00
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
int BH_QueueEmpty(BH_Queue *queue);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the size of the \a queue.
|
|
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
|
|
|
|
* \return Returns the size of the queue.
|
|
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
size_t BH_QueueSize(BH_Queue *queue);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the capacity of the \a queue.
|
|
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
|
|
|
|
* \return Returns the capacity of the queue.
|
|
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
size_t BH_QueueCapacity(BH_Queue *queue);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the iterator to the next element in the \a queue.
|
|
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param queue Queue pointer
|
|
|
|
|
* \param iter Iterator
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \return On success, returns new iterator value for the next element.
|
|
|
|
|
* \return On failure, returns NULL pointer.
|
2025-01-18 17:24:36 +03:00
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
void *BH_QueueIterNext(BH_Queue *queue,
|
|
|
|
|
void *iter);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-02-03 15:18:57 +03:00
|
|
|
* Returns the value, pointed by the \a iter.
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
2025-02-03 15:18:57 +03:00
|
|
|
* \param iter Iterator
|
2025-01-18 17:24:36 +03:00
|
|
|
*
|
|
|
|
|
* \return Returns value, pointed by iterator.
|
|
|
|
|
*/
|
2025-01-30 13:53:26 +03:00
|
|
|
void *BH_QueueIterValue(void *iter);
|
2025-01-18 17:24:36 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* BH_QUEUE_H */
|