Landtiger LPC1768 C BigLib 1
A self made, custom C library for the LandTiger board.
 
Loading...
Searching...
No Matches
cl_prioqueue.h
Go to the documentation of this file.
1#ifndef __CL_PRIOQUEUE_H
2#define __CL_PRIOQUEUE_H
3
4#include "allocator.h"
5#include "cl_types.h"
6#include "types.h"
7
8#include <stdbool.h>
9
10// FORWARD DECLARATIONS
11typedef struct __PQueue CL_PQueue;
12
13// MACROS
14
15#define CL_PQUEUE_FOREACH(__type, __name, __queue, ...) \
16 for (u32 __i = 0; __i < CL_PQueueSize(__queue); __i++) \
17 { \
18 __type *__pq_arr = (__type *)CL_PQueueAsArray(__queue); \
19 __type __name = __pq_arr[__i]; \
20 __VA_ARGS__ \
21 }
22
23// TYPES
24
29typedef int (*CL_PQueueCompareFn)(const void *, const void *);
30
31// FUNCTIONS
32
41
48
52void CL_PQueueFree(CL_PQueue *const pq);
53
58CL_Error CL_PQueueEnqueue(CL_PQueue *const pq, const void *const elem);
59
64CL_Error CL_PQueueDequeue(CL_PQueue *const pq, void *out_elem);
65
70CL_Error CL_PQueuePeek(const CL_PQueue *const pq, void *out_elem);
71
75u32 CL_PQueueSize(const CL_PQueue *const pq);
76
80bool CL_PQueueIsEmpty(const CL_PQueue *const pq);
81
82/*
83// ARRAY ACCESS
84
88void *CL_PQueueAsArray(const CL_PQueue *const pq);
89*/
90
91#endif
int(* CL_PQueueCompareFn)(const void *, const void *)
bool CL_PQueueIsEmpty(const CL_PQueue *const pq)
Checks if the priority queue is empty.
void CL_PQueueFree(CL_PQueue *const pq)
Frees the memory previously assigned to the priority queue.
CL_Error CL_PQueuePeek(const CL_PQueue *const pq, void *out_elem)
Gets the element with the highest priority from the priority queue without removing it.
CL_Error CL_PQueueDequeue(CL_PQueue *const pq, void *out_elem)
Removes the element with the highest priority from the priority queue.
u32 CL_PQueueSize(const CL_PQueue *const pq)
Gets the number of elements in the priority queue.
CL_PQueue * CL_PQueueAlloc(MEM_Allocator *const alloc, u32 elem_sz, CL_PQueueCompareFn compare_fn)
Initializes a priority queue with a default capacity.
CL_PQueue * CL_PQueueAllocWithCapacity(MEM_Allocator *const alloc, u32 capacity, u32 elem_sz, CL_PQueueCompareFn compare_fn)
Initializes a priority queue with the allocated memory provided by the user.
CL_Error CL_PQueueEnqueue(CL_PQueue *const pq, const void *const elem)
Adds an element to the priority queue.
CL_Error
Specify this in the size parameter of the collections initialization to tell the library that the num...
Definition cl_types.h:24
CL_PQueueCompareFn compare_fn
The comparison function.
uint32_t u32
Definition types.h:6