Crater Container Library 0.2.0
|
|
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
Definition in file minmax_heap.h.
Go to the source code of this file.
Functions | |
void | cr8r_mmheap_ify (cr8r_vec *, cr8r_vec_ft *) |
Turn a vector into a minmax heap in place in linear time. | |
void * | cr8r_mmheap_peek_min (cr8r_vec *, cr8r_vec_ft *) |
Get the min element of a minmax heap. More... | |
void * | cr8r_mmheap_peek_max (cr8r_vec *, cr8r_vec_ft *) |
Get the max element of a minmax heap. More... | |
void | cr8r_mmheap_sift_up (cr8r_vec *, cr8r_vec_ft *, void *e) |
Move an element up the minmax heap as necessary to restore the heap invariant. More... | |
void | cr8r_mmheap_sift_down (cr8r_vec *, cr8r_vec_ft *, void *e) |
Move an element down the minmax heap as necessary to restore the heap invariant. More... | |
bool | cr8r_mmheap_push (cr8r_vec *, cr8r_vec_ft *, const void *e) |
Add a new element to the minmax heap. More... | |
bool | cr8r_mmheap_pop_min (cr8r_vec *, cr8r_vec_ft *, void *o) |
Remove the min element from the minmax heap. More... | |
bool | cr8r_mmheap_pop_max (cr8r_vec *, cr8r_vec_ft *, void *o) |
Remove the max element from the minmax heap. More... | |
bool | cr8r_mmheap_pop_idx (cr8r_vec *, cr8r_vec_ft *, void *o, uint64_t i) |
Remove element at index i from the minmax heap. More... | |
bool | cr8r_mmheap_pushpop_min (cr8r_vec *, cr8r_vec_ft *, const void *e, void *o) |
Push an element and then pop the min element in one operation. More... | |
bool | cr8r_mmheap_pushpop_max (cr8r_vec *, cr8r_vec_ft *, const void *e, void *o) |
Push an element and then pop the max element in one operation. More... | |
void* cr8r_mmheap_peek_min | ( | cr8r_vec * | , |
cr8r_vec_ft * | |||
) |
Get the min element of a minmax heap.
Simply returns a pointer to the root element, or NULL if len is 0
void* cr8r_mmheap_peek_max | ( | cr8r_vec * | , |
cr8r_vec_ft * | |||
) |
Get the max element of a minmax heap.
Simply returns a pointer to the max element (which is the last element if there are fewer than 3, otherwise the element at index 1 or 2), or NULL if len is 0
void cr8r_mmheap_sift_up | ( | cr8r_vec * | , |
cr8r_vec_ft * | , | ||
void * | e | ||
) |
Move an element up the minmax heap as necessary to restore the heap invariant.
Typically used if one element's value has been changed but the heap invariant is otherwise intact Whether sift_up or sift_down is appropriate for a changed element in a minmax heap depends not only on whether the element was increased or decreased but also on whether it is in a min layer or max layer
[in] | e | pointer to the element to sift up. Typically you will have this pointer, if you only have the index cr8r_vec_get can be used to do the self->base + i*ft->base.size calculation for you. |
void cr8r_mmheap_sift_down | ( | cr8r_vec * | , |
cr8r_vec_ft * | , | ||
void * | e | ||
) |
Move an element down the minmax heap as necessary to restore the heap invariant.
Typically used if one element's value has been changed but the heap invariant is otherwise intact Whether sift_up or sift_down is appropriate for a changed element in a minmax heap depends not only on whether the element was increased or decreased but also on whether it is in a min layer or max layer
[in] | e | pointer to the element to sift up. Typically you will have this pointer, if you only have the index cr8r_vec_get can be used to do the self->base + i*ft->base.size calculation for you. |
bool cr8r_mmheap_push | ( | cr8r_vec * | , |
cr8r_vec_ft * | , | ||
const void * | e | ||
) |
Add a new element to the minmax heap.
[in] | e | pointer to the element to insert, which is COPIED into the heap |
bool cr8r_mmheap_pop_min | ( | cr8r_vec * | , |
cr8r_vec_ft * | , | ||
void * | o | ||
) |
Remove the min element from the minmax heap.
[in] | o | pointer to COPY the heap element to before removing it, cannot be NULL |
bool cr8r_mmheap_pop_max | ( | cr8r_vec * | , |
cr8r_vec_ft * | , | ||
void * | o | ||
) |
Remove the max element from the minmax heap.
[out] | o | pointer to COPY the heap element to before removing it, cannot be NULL |
bool cr8r_mmheap_pop_idx | ( | cr8r_vec * | , |
cr8r_vec_ft * | , | ||
void * | o, | ||
uint64_t | i | ||
) |
Remove element at index i from the minmax heap.
Note that if you have a pointer e to an element of a heap vec with ft ft, you can get its index i as i = (e - vec->base)/ft->base.size
[out] | o | pointer to COPY the heap element to before removing it, cannot be NULL |
[in] | i | index to pop |
bool cr8r_mmheap_pushpop_min | ( | cr8r_vec * | , |
cr8r_vec_ft * | , | ||
const void * | e, | ||
void * | o | ||
) |
Push an element and then pop the min element in one operation.
This function allows the common push-pop operation to be optimized, although it is currently no different from just calling both functions in sequence
[in] | e | pointer to the element to insert, which is COPIED into the heap |
[out] | o | pointer to COPY the popped element to before removing it, cannot be NULL |
bool cr8r_mmheap_pushpop_max | ( | cr8r_vec * | , |
cr8r_vec_ft * | , | ||
const void * | e, | ||
void * | o | ||
) |
Push an element and then pop the max element in one operation.
This function allows the common push-pop operation to be optimized, although it is currently no different from just calling both functions in sequence
[in] | e | pointer to the element to insert, which is COPIED into the heap |
[out] | o | pointer to COPY the popped element to before removing it, cannot be NULL |