39 lines
1.7 KiB
C
39 lines
1.7 KiB
C
#ifndef INCLUDED_C_INDEXPQ_H
|
|
#define INCLUDED_C_INDEXPQ_H
|
|
|
|
#ifndef INCLUDED_C_BASE_H
|
|
#include <c_Base.h>
|
|
#endif /*INCLUDED_C_BASE_H*/
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
// User priority comparison callback: returns <0 if a < b, 0 if a == b, >0 if a > b
|
|
typedef int (*c_IndexPQ_Compare_f)(const void* a, const void* b);
|
|
|
|
typedef struct {
|
|
void* keys_data; // Array storing user element data values indexed by ID
|
|
c_size_t* heap; // Binary heap array containing element IDs
|
|
c_size_t* inverse_heap; // Maps element ID -> its current position index within the heap array
|
|
int obj_size; // Memory size of each user element structure
|
|
c_size_t max_size; // Maximum number of items the Indexed PQ can handle
|
|
c_size_t size; // Current number of active elements inside the queue
|
|
c_IndexPQ_Compare_f compare; // User-defined priority comparison callback
|
|
} c_IndexPQ_t;
|
|
|
|
c_err_t c_IndexPQ_Init(c_IndexPQ_t* self, int obj_size, c_size_t max_size, c_IndexPQ_Compare_f compare);
|
|
void c_IndexPQ_Destroy(c_IndexPQ_t* self);
|
|
|
|
c_err_t c_IndexPQ_Push(c_IndexPQ_t* self, c_size_t id, const void* obj);
|
|
c_err_t c_IndexPQ_Pop(c_IndexPQ_t* self, c_size_t* out_id, void* out_obj);
|
|
c_err_t c_IndexPQ_Change(c_IndexPQ_t* self, c_size_t id, const void* new_obj);
|
|
c_bool_t c_IndexPQ_Contains(const c_IndexPQ_t* self, c_size_t id);
|
|
|
|
void* c_IndexPQ_PeekValue(c_IndexPQ_t* self);
|
|
long long c_IndexPQ_PeekID(c_IndexPQ_t* self);
|
|
c_size_t c_IndexPQ_GetSize(const c_IndexPQ_t* self);
|
|
c_bool_t c_IndexPQ_IsEmpty(const c_IndexPQ_t* self);
|
|
|
|
#endif /*INCLUDED_C_INDEXPQ_H*/
|