#ifndef INCLUDED_C_INDEXMINPQ_H #define INCLUDED_C_INDEXMINPQ_H #ifndef INCLUDED_C_TYPES_H #include #endif /*INCLUDED_C_TYPES_H*/ /* ------------------------------------------------------------------------------------------------------------------ */ /* */ typedef struct { void* keys; // Flat array storing user's complex items (indexed by external ID) c_size_t element_size; // Size of each element in bytes c_size_t max_items; // Maximum external ID capacity (0 to max_items - 1) c_size_t size; // Current active element count inside the heap long long* pq; // Heap array: map heap position -> external ID long long* qp; // Inverted index array: map external ID -> heap position (-1 if not in heap) int (*compar)(const void*, const void*); // Custom comparison rule pointer } c_IndexMinPQ_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ c_err_t c_IndexMinPQ_Init(c_IndexMinPQ_t* pq_inst, c_size_t max_items, c_size_t element_size, int (*compar)(const void*, const void*)); void c_IndexMinPQ_Destroy(c_IndexMinPQ_t* pq_inst); c_bool_t c_IndexMinPQ_Contains(c_IndexMinPQ_t* pq_inst, c_size_t ext_id); c_err_t c_IndexMinPQ_Push(c_IndexMinPQ_t* pq_inst, c_size_t ext_id, const void* element); c_err_t c_IndexMinPQ_Pop(c_IndexMinPQ_t* pq_inst, c_size_t* out_ext_id, void* out_element_buffer) ; c_err_t c_IndexMinPQ_ChangeKey(c_IndexMinPQ_t* pq_inst, c_size_t ext_id, const void* new_element); void* c_IndexMinPQ_Peek(c_IndexMinPQ_t* pq_inst, c_size_t* out_ext_id); #endif /*INCLUDED_C_INDEXMINPQ_H*/