|
C Container Collection (CCC)
|
The Flat Priority Queue Interface. More...


Go to the source code of this file.
The Flat Priority Queue Interface.
A flat priority queue is a contiguous container storing elements in heap order. This offers tightly packed data for efficient push, pop, min/max operations in O(lg N) time.
A flat priority queue can use memory sources from the stack, heap, or data segment and can be initialized at compile or runtime. The container offers efficient initialization options such as an O(N) heap building initializer. The flat priority queue also offers a destructive heap sort option if the user desires an in-place strict O(N * log(N)) and O(1) space sort that does not use recursion.
Many functions in the interface request a temporary argument be passed as a swap slot. This is because a flat priority queue is backed by a binary heap and swaps elements to maintain its properties. Because the user may decide the flat priority queue has no allocation permission, the user must provide this swap slot. An easy way to do this in C99 and later is with anonymous compound literal references. For example, if we have a int flat priority queue we can provide a temporary slot inline to a function as follows.
Any user defined struct can also use this technique.
This is the preferred method because the storage remains anonymous and inaccessible to other code in the calling scope.
To shorten names in the interface, define the following preprocessor directive at the top of your file.
All types and functions can then be written without the CCC_ prefix.
Initialization Interface | |
Initialize the container with memory, callbacks, and permissions. | |
| #define | CCC_flat_priority_queue_initialize( data_pointer, type_name, order, compare, allocate, context_data, capacity) |
| Initialize a priority_queue as a min or max heap. | |
| #define | CCC_flat_priority_queue_heapify_initialize( data_pointer, type_name, order, compare, allocate, context_data, capacity, size) |
| Partial order an array of elements as a min or max heap. O(N). | |
| #define | CCC_flat_priority_queue_from(order, compare, allocate, context_data, optional_capacity, compound_literal_array...) |
| Partial order a compound literal array of elements as a min or max heap. O(N). | |
| #define | CCC_flat_priority_queue_with_capacity( type_name, order, compare, allocate, context_data, capacity) |
| Initialize a Flat_priority_queue with a capacity. | |
| CCC_Result | CCC_flat_priority_queue_copy (CCC_Flat_priority_queue *destination, CCC_Flat_priority_queue const *source, CCC_Allocator *allocate) |
| Copy the priority_queue from source to newly initialized destination. | |
| CCC_Result | CCC_flat_priority_queue_reserve (CCC_Flat_priority_queue *priority_queue, size_t to_add, CCC_Allocator *allocate) |
| Reserves space for at least to_add more elements. | |
Insert and Remove Interface | |
Insert or remove elements from the flat priority queue. | |
| #define | CCC_flat_priority_queue_emplace(priority_queue_pointer, type_compound_literal...) |
| Write a type directly to a priority queue slot. O(lgN). | |
| #define | CCC_flat_priority_queue_update_with( priority_queue_pointer, type_pointer, update_closure_over_T...) |
| Update the user type stored in the priority queue directly. O(lgN). | |
| #define | CCC_flat_priority_queue_increase_with( flat_priority_queue_pointer, type_pointer, increase_closure_over_T...) |
| Increase the user type stored in the priority queue directly. O(lgN). | |
| #define | CCC_flat_priority_queue_decrease_with( flat_priority_queue_pointer, type_pointer, decrease_closure_over_T...) |
| Increase the user type stored in the priority queue directly. O(lgN). | |
| CCC_Result | CCC_flat_priority_queue_heapify (CCC_Flat_priority_queue *priority_queue, void *temp, void *type_array, size_t count, size_t sizeof_type) |
| Copy input array into the flat_priority_queue, organizing into heap. O(N). | |
| CCC_Result | CCC_flat_priority_queue_heapify_inplace (CCC_Flat_priority_queue *priority_queue, void *temp, size_t count) |
| Order count elements of the underlying priority_queue Buffer as an flat_priority_queue. | |
| void * | CCC_flat_priority_queue_push (CCC_Flat_priority_queue *priority_queue, void const *type, void *temp) |
| Pushes element pointed to at e into flat_priority_queue. O(lgN). | |
| CCC_Result | CCC_flat_priority_queue_pop (CCC_Flat_priority_queue *priority_queue, void *temp) |
| Pop the front element (min or max) element in the flat_priority_queue. O(lgN). | |
| CCC_Result | CCC_flat_priority_queue_erase (CCC_Flat_priority_queue *priority_queue, void *type, void *temp) |
| Erase element e that is a handle to the stored flat_priority_queue element. | |
| void * | CCC_flat_priority_queue_update (CCC_Flat_priority_queue *priority_queue, void *type, void *temp, CCC_Type_modifier *modify, void *context) |
| Update e that is a handle to the stored priority_queue element. O(lgN). | |
| void * | CCC_flat_priority_queue_increase (CCC_Flat_priority_queue *priority_queue, void *type, void *temp, CCC_Type_modifier *modify, void *context) |
| Increase e that is a handle to the stored flat_priority_queue element. O(lgN). | |
| void * | CCC_flat_priority_queue_decrease (CCC_Flat_priority_queue *priority_queue, void *type, void *temp, CCC_Type_modifier *modify, void *context) |
| Decrease e that is a handle to the stored flat_priority_queue element. O(lgN). | |
Container Types | |
Types available in the container interface. | |
| typedef struct CCC_Flat_priority_queue | CCC_Flat_priority_queue |
| A container offering direct storage and sorting of user data by heap order. | |
Deallocation Interface | |
Deallocate the container or destroy the heap invariants. | |
| CCC_Buffer | CCC_flat_priority_queue_heapsort (CCC_Flat_priority_queue *priority_queue, void *temp) |
Destroys the priority_queue by sorting its data and returning the underlying buffer. The data is sorted in O(N * log(N)) time and O(1) space. | |
| CCC_Result | CCC_flat_priority_queue_clear (CCC_Flat_priority_queue *priority_queue, CCC_Type_destructor *destroy) |
| Clears the priority_queue calling destroy on every element if provided. O(1)-O(N). | |
| CCC_Result | CCC_flat_priority_queue_clear_and_free (CCC_Flat_priority_queue *priority_queue, CCC_Type_destructor *destroy) |
| Clears the priority_queue calling destroy on every element if provided and frees the underlying buffer. O(1)-O(N). | |
| CCC_Result | CCC_flat_priority_queue_clear_and_free_reserve (CCC_Flat_priority_queue *priority_queue, CCC_Type_destructor *destructor, CCC_Allocator *allocate) |
| Frees all slots in the priority_queue and frees the underlying Buffer that was previously dynamically reserved with the reserve function. | |
State Interface | |
Obtain state from the container. | |
| void * | CCC_flat_priority_queue_front (CCC_Flat_priority_queue const *priority_queue) |
| Return a pointer to the front (min or max) element in the flat_priority_queue. O(1). | |
| CCC_Tribool | CCC_flat_priority_queue_is_empty (CCC_Flat_priority_queue const *priority_queue) |
| Returns true if the priority_queue is empty false if not. O(1). | |
| CCC_Count | CCC_flat_priority_queue_count (CCC_Flat_priority_queue const *priority_queue) |
| Returns the count of the priority_queue active slots. | |
| CCC_Count | CCC_flat_priority_queue_capacity (CCC_Flat_priority_queue const *priority_queue) |
| Returns the capacity of the priority_queue representing total possible slots. | |
| void * | CCC_flat_priority_queue_data (CCC_Flat_priority_queue const *priority_queue) |
| Return a pointer to the base of the backing array. O(1). | |
| CCC_Tribool | CCC_flat_priority_queue_validate (CCC_Flat_priority_queue const *priority_queue) |
| Verifies the internal invariants of the priority_queue hold. | |
| CCC_Order | CCC_flat_priority_queue_order (CCC_Flat_priority_queue const *priority_queue) |
| Return the order used to initialize the flat_priority_queue. | |
| #define CCC_flat_priority_queue_decrease_with | ( | flat_priority_queue_pointer, | |
| type_pointer, | |||
| decrease_closure_over_T... | |||
| ) |
Increase the user type stored in the priority queue directly. O(lgN).
| [in] | flat_priority_queue_pointer | a pointer to the flat priority queue. |
| [in] | type_pointer | a pointer to the user type being updated. |
| [in] | decrease_closure_over_T | the semicolon separated statements to execute on the user type at T (optionally wrapping {code here} in braces may help with formatting). This closure may safely modify the key used to track the user element's priority in the priority queue. |
Note that if this priority queue is min or max, the runtime is the same.
| #define CCC_flat_priority_queue_emplace | ( | priority_queue_pointer, | |
| type_compound_literal... | |||
| ) |
Write a type directly to a priority queue slot. O(lgN).
| [in] | priority_queue_pointer | a pointer to the priority queue. |
| [in] | type_compound_literal | the compound literal or direct scalar type. |
| #define CCC_flat_priority_queue_from | ( | order, | |
| compare, | |||
| allocate, | |||
| context_data, | |||
| optional_capacity, | |||
| compound_literal_array... | |||
| ) |
Partial order a compound literal array of elements as a min or max heap. O(N).
| [in] | order | CCC_ORDER_LESSER or CCC_ORDER_GREATER for min or max heap, respectively. |
| [in] | compare | the user defined comparison function for user types. |
| [in] | allocate | the allocation function or NULL if no allocation. |
| [in] | context_data | any context data needed for destruction of elements. |
| [in] | optional_capacity | the optional capacity larger than the input compound literal array array to reserve. If capacity provided is less than the size of the input compound literal array, the capacity is set to the size of the input compound literal array. If not needed, simply leave as zero. |
| [in] | compound_literal_array | the initializer of the type stored in flat priority queue (e.g. (int[]){1,2,3}). |
Initialize a dynamic Flat_priority_queue with capacity equal to size.
Initialize a dynamic Flat_priority_queue with a large capacity.
Only dynamic priority queues may be initialized this way. For static or stack based initialization of fixed buffers with contents known at compile time, see the CCC_flat_priority_queue_initialize() macro.
| #define CCC_flat_priority_queue_heapify_initialize | ( | data_pointer, | |
| type_name, | |||
| order, | |||
| compare, | |||
| allocate, | |||
| context_data, | |||
| capacity, | |||
| size | |||
| ) |
Partial order an array of elements as a min or max heap. O(N).
| [in] | data_pointer | a pointer to an array of user types or NULL. |
| [in] | type_name | the name of the user type. |
| [in] | order | CCC_ORDER_LESSER or CCC_ORDER_GREATER for min or max heap, respectively. |
| [in] | compare | the user defined comparison function for user types. |
| [in] | allocate | the allocation function or NULL if no allocation. |
| [in] | context_data | any context data needed for destruction of elements. |
| [in] | capacity | the capacity of contiguous elements at data_pointer. |
| [in] | size | the size <= capacity. |
| #define CCC_flat_priority_queue_increase_with | ( | flat_priority_queue_pointer, | |
| type_pointer, | |||
| increase_closure_over_T... | |||
| ) |
Increase the user type stored in the priority queue directly. O(lgN).
| [in] | flat_priority_queue_pointer | a pointer to the flat priority queue. |
| [in] | type_pointer | a pointer to the user type being updated. |
| [in] | increase_closure_over_T | the semicolon separated statements to execute on the user type at T (optionally wrapping {code here} in braces may help with formatting). This closure may safely modify the key used to track the user element's priority in the priority queue. |
Note that if this priority queue is min or max, the runtime is the same.
| #define CCC_flat_priority_queue_initialize | ( | data_pointer, | |
| type_name, | |||
| order, | |||
| compare, | |||
| allocate, | |||
| context_data, | |||
| capacity | |||
| ) |
Initialize a priority_queue as a min or max heap.
| [in] | data_pointer | a pointer to an array of user types or NULL. |
| [in] | type_name | the name of the user type. |
| [in] | order | CCC_ORDER_LESSER or CCC_ORDER_GREATER for min or max heap, respectively. |
| [in] | compare | the user defined comarison function for user types. |
| [in] | allocate | the allocation function or NULL if no allocation. |
| [in] | context_data | any context data needed for destruction of elements. |
| [in] | capacity | the capacity of contiguous elements at data_pointer. |
| #define CCC_flat_priority_queue_update_with | ( | priority_queue_pointer, | |
| type_pointer, | |||
| update_closure_over_T... | |||
| ) |
Update the user type stored in the priority queue directly. O(lgN).
| [in] | priority_queue_pointer | a pointer to the flat priority queue. |
| [in] | type_pointer | a pointer to the user type being updated. |
| [in] | update_closure_over_T | the semicolon separated statements to execute on the user type at T (optionally wrapping {code here} in braces may help with formatting). This closure may safely modify the key used to track the user element's priority in the priority queue. |
Note that whether the key increases or decreases does not affect runtime.
| #define CCC_flat_priority_queue_with_capacity | ( | type_name, | |
| order, | |||
| compare, | |||
| allocate, | |||
| context_data, | |||
| capacity | |||
| ) |
Initialize a Flat_priority_queue with a capacity.
| [in] | type_name | the name of the user type. |
| [in] | order | CCC_ORDER_LESSER or CCC_ORDER_GREATER for min or max heap, respectively. |
| [in] | compare | the user defined comparison function for user types. |
| [in] | allocate | the allocation function or NULL if no allocation. |
| [in] | context_data | any context data needed for destruction of elements. |
| [in] | capacity | the capacity of contiguous elements at data_pointer. |
Initialize a dynamic Flat_priority_queue.
Only dynamic Flat_priority_queues may be initialized this way. For static or stack based initialization of fixed flat_priority_queues with contents known at compile time, see the CCC_flat_priority_queue_initialize() macro.
| typedef struct CCC_Flat_priority_queue CCC_Flat_priority_queue |
A container offering direct storage and sorting of user data by heap order.
A flat priority queue can be initialized on the stack, heap, or data segment at runtime or compile time.
| CCC_Count CCC_flat_priority_queue_capacity | ( | CCC_Flat_priority_queue const * | priority_queue | ) |
Returns the capacity of the priority_queue representing total possible slots.
| [in] | priority_queue | a pointer to the flat priority queue. |
| CCC_Result CCC_flat_priority_queue_clear | ( | CCC_Flat_priority_queue * | priority_queue, |
| CCC_Type_destructor * | destroy | ||
| ) |
Clears the priority_queue calling destroy on every element if provided. O(1)-O(N).
| [in] | priority_queue | a pointer to the flat priority queue. |
| [in] | destroy | the destructor function or NULL if not needed. |
Note that because the priority queue is flat there is no need to free elements stored in the flat_priority_queue. However, the destructor is free to manage cleanup in other parts of user code as needed upon destruction of each element.
If the destructor is NULL, the function is O(1) and no attempt is made to free capacity of the flat_priority_queue.
| CCC_Result CCC_flat_priority_queue_clear_and_free | ( | CCC_Flat_priority_queue * | priority_queue, |
| CCC_Type_destructor * | destroy | ||
| ) |
Clears the priority_queue calling destroy on every element if provided and frees the underlying buffer. O(1)-O(N).
| [in] | priority_queue | a pointer to the flat priority queue. |
| [in] | destroy | the destructor function or NULL if not needed. |
Note that because the priority queue is flat there is no need to free elements stored in the flat_priority_queue. However, the destructor is free to manage cleanup in other parts of user code as needed upon destruction of each element.
If the destructor is NULL, the function is O(1) and only relies on the runtime of the provided allocation function free operation.
| CCC_Result CCC_flat_priority_queue_clear_and_free_reserve | ( | CCC_Flat_priority_queue * | priority_queue, |
| CCC_Type_destructor * | destructor, | ||
| CCC_Allocator * | allocate | ||
| ) |
Frees all slots in the priority_queue and frees the underlying Buffer that was previously dynamically reserved with the reserve function.
| [in] | priority_queue | the priority_queue to be cleared. |
| [in] | destructor | the destructor for each element. NULL can be passed if no maintenance is required on the elements in the priority_queue before their slots are dropped. |
| [in] | allocate | the required allocation function to provide to a dynamically reserved flat_priority_queue. Any context data provided upon initialization will be passed to the allocation function when called. |
This function covers the edge case of reserving a dynamic capacity for a flat_priority_queue at runtime but denying the priority_queue allocation permission to resize. This can help prevent a priority_queue from growing untree. The user in this case knows the priority_queue does not have allocation permission and therefore no further memory will be dedicated to the flat_priority_queue.
However, to free the priority_queue in such a case this function must be used because the priority_queue has no ability to free itself. Just as the allocation function is required to reserve memory so to is it required to free memory.
This function will work normally if called on a priority_queue with allocation permission however the normal CCC_flat_priority_queue_clear_and_free is sufficient for that use case.
| CCC_Result CCC_flat_priority_queue_copy | ( | CCC_Flat_priority_queue * | destination, |
| CCC_Flat_priority_queue const * | source, | ||
| CCC_Allocator * | allocate | ||
| ) |
Copy the priority_queue from source to newly initialized destination.
| [in] | destination | the destination that will copy the source flat_priority_queue. |
| [in] | source | the source of the flat_priority_queue. |
| [in] | allocate | the allocation function in case resizing of destination is needed. |
Note that there are two ways to copy data from source to destination: provide sufficient memory and pass NULL as allocate, or allow the copy function to take care of allocation for the copy.
Manual memory management with no allocation function provided.
The above requires destination capacity be greater than or equal to source capacity. Here is memory management handed over to the copy function.
The above allows destination to have a capacity less than that of the source as long as copy has been provided an allocation function to resize destination. Note that this would still work if copying to a destination that the user wants as a fixed size flat_priority_queue.
The above sets up destination with fixed size while source is a dynamic flat_priority_queue. Because an allocation function is provided, the destination is resized once for the copy and retains its fixed size after the copy is complete. This would require the user to manually free the underlying Buffer at destination eventually if this method is used. Usually it is better to allocate the memory explicitly before the copy if copying between ring buffers.
These options allow users to stay consistent across containers with their memory management strategies.
| CCC_Count CCC_flat_priority_queue_count | ( | CCC_Flat_priority_queue const * | priority_queue | ) |
Returns the count of the priority_queue active slots.
| [in] | priority_queue | a pointer to the flat priority queue. |
| void * CCC_flat_priority_queue_data | ( | CCC_Flat_priority_queue const * | priority_queue | ) |
Return a pointer to the base of the backing array. O(1).
| [in] | priority_queue | a pointer to the priority queue. |
| void * CCC_flat_priority_queue_decrease | ( | CCC_Flat_priority_queue * | priority_queue, |
| void * | type, | ||
| void * | temp, | ||
| CCC_Type_modifier * | modify, | ||
| void * | context | ||
| ) |
Decrease e that is a handle to the stored flat_priority_queue element. O(lgN).
| [in] | priority_queue | a pointer to the flat priority queue. |
| [in] | type | a pointer to the stored priority_queue element. Must be in the flat_priority_queue. |
| [in] | temp | a pointer to a dummy user type that will be used for swapping. |
| [in] | modify | the update function to act on e. |
| [in] | context | any context data needed for the update function. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
| CCC_Result CCC_flat_priority_queue_erase | ( | CCC_Flat_priority_queue * | priority_queue, |
| void * | type, | ||
| void * | temp | ||
| ) |
Erase element e that is a handle to the stored flat_priority_queue element.
| [in] | priority_queue | a pointer to the priority queue. |
| [in] | type | a pointer to the stored priority_queue element. Must be in the flat_priority_queue. |
| [in] | temp | a pointer to a dummy user type that will be used for swapping. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
Note that the reference to type is invalidated after this call.
| void * CCC_flat_priority_queue_front | ( | CCC_Flat_priority_queue const * | priority_queue | ) |
Return a pointer to the front (min or max) element in the flat_priority_queue. O(1).
| [in] | priority_queue | a pointer to the priority queue. |
| CCC_Result CCC_flat_priority_queue_heapify | ( | CCC_Flat_priority_queue * | priority_queue, |
| void * | temp, | ||
| void * | type_array, | ||
| size_t | count, | ||
| size_t | sizeof_type | ||
| ) |
Copy input array into the flat_priority_queue, organizing into heap. O(N).
| [in] | priority_queue | a pointer to the priority queue. |
| [in] | temp | a pointer to an additional element of array type for swapping. |
| [in] | type_array | an array of elements of the same size as the type used to initialize flat_priority_queue. |
| [in] | count | the number of contiguous elements at type_array. |
| [in] | sizeof_type | size of each element in type_array matching element size of flat_priority_queue. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
Note that this version of heapify copies elements from the input array. If an in place heapify is required use the initializer version of this method.
| CCC_Result CCC_flat_priority_queue_heapify_inplace | ( | CCC_Flat_priority_queue * | priority_queue, |
| void * | temp, | ||
| size_t | count | ||
| ) |
Order count elements of the underlying priority_queue Buffer as an flat_priority_queue.
| [in] | priority_queue | a pointer to the flat priority queue. |
| [in] | temp | a pointer to a dummy user type that will be used for swapping. |
| [in] | count | the number count of elements where 0 < (n + 1) <= capacity. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
This is another method to order a heap that already has all the elements one needs sorted. The underlying Buffer will be interpreted to have count valid elements starting at index 0 to index count - 1.
| CCC_Buffer CCC_flat_priority_queue_heapsort | ( | CCC_Flat_priority_queue * | priority_queue, |
| void * | temp | ||
| ) |
Destroys the priority_queue by sorting its data and returning the underlying buffer. The data is sorted in O(N * log(N)) time and O(1) space.
| [in] | priority_queue | the priority_queue to be sorted and destroyed. |
| [in] | temp | a pointer to a dummy user type that will be used for swapping. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
The underlying memory storage source for the flat_priority_queue, a buffer, is not moved or copied during the sort. If a copy of the sorted data is preferred copy the data the data to another initialized priority_queue with the CCC_flat_priority_queue_copy function first then sort that copy.
The sort is not inherently stable and uses the provided comparison function to the priority_queue to order the elements.
| void * CCC_flat_priority_queue_increase | ( | CCC_Flat_priority_queue * | priority_queue, |
| void * | type, | ||
| void * | temp, | ||
| CCC_Type_modifier * | modify, | ||
| void * | context | ||
| ) |
Increase e that is a handle to the stored flat_priority_queue element. O(lgN).
| [in] | priority_queue | a pointer to the flat priority queue. |
| [in] | type | a pointer to the stored priority_queue element. Must be in the flat_priority_queue. |
| [in] | temp | a pointer to a dummy user type that will be used for swapping. |
| [in] | modify | the update function to act on e. |
| [in] | context | any context data needed for the update function. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
| CCC_Tribool CCC_flat_priority_queue_is_empty | ( | CCC_Flat_priority_queue const * | priority_queue | ) |
Returns true if the priority_queue is empty false if not. O(1).
| [in] | priority_queue | a pointer to the flat priority queue. |
| CCC_Order CCC_flat_priority_queue_order | ( | CCC_Flat_priority_queue const * | priority_queue | ) |
Return the order used to initialize the flat_priority_queue.
| [in] | priority_queue | a pointer to the flat priority queue. |
| CCC_Result CCC_flat_priority_queue_pop | ( | CCC_Flat_priority_queue * | priority_queue, |
| void * | temp | ||
| ) |
Pop the front element (min or max) element in the flat_priority_queue. O(lgN).
| [in] | priority_queue | a pointer to the priority queue. |
| [in] | temp | a pointer to a dummy user type that will be used for swapping. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
| void * CCC_flat_priority_queue_push | ( | CCC_Flat_priority_queue * | priority_queue, |
| void const * | type, | ||
| void * | temp | ||
| ) |
Pushes element pointed to at e into flat_priority_queue. O(lgN).
| [in] | priority_queue | a pointer to the priority queue. |
| [in] | type | a pointer to the user element of same type as in flat_priority_queue. |
| [in] | temp | a pointer to a dummy user type that will be used for swapping. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
| CCC_Result CCC_flat_priority_queue_reserve | ( | CCC_Flat_priority_queue * | priority_queue, |
| size_t | to_add, | ||
| CCC_Allocator * | allocate | ||
| ) |
Reserves space for at least to_add more elements.
| [in] | priority_queue | a pointer to the flat priority queue. |
| [in] | to_add | the number of elements to add to the current size. |
| [in] | allocate | the allocation function to use to reserve memory. |
This function can be used for a dynamic priority_queue with or without allocation permission. If the priority_queue has allocation permission, it will reserve the required space and later resize if more space is needed.
If the priority_queue has been initialized with no allocation permission and no memory this function can serve as a one-time reservation. This is helpful when a fixed size is needed but that size is only known dynamically at runtime. To free the priority_queue in such a case see the CCC_flat_priority_queue_clear_and_free_reserve function.
| void * CCC_flat_priority_queue_update | ( | CCC_Flat_priority_queue * | priority_queue, |
| void * | type, | ||
| void * | temp, | ||
| CCC_Type_modifier * | modify, | ||
| void * | context | ||
| ) |
Update e that is a handle to the stored priority_queue element. O(lgN).
| [in] | priority_queue | a pointer to the flat priority queue. |
| [in] | type | a pointer to the stored priority_queue element. Must be in the flat_priority_queue. |
| [in] | temp | a pointer to a dummy user type that will be used for swapping. |
| [in] | modify | the update function to act on e. |
| [in] | context | any context data needed for the update function. |
A simple way to provide a temp for swapping is with an inline compound literal reference provided directly to the function argument &(name_of_type){}.
| CCC_Tribool CCC_flat_priority_queue_validate | ( | CCC_Flat_priority_queue const * | priority_queue | ) |
Verifies the internal invariants of the priority_queue hold.
| [in] | priority_queue | a pointer to the flat priority queue. |