/* *min heap pop */ element* min_heap_pop(struct min_heap* s) { if (s->n) { element* e = *s->p; min_heap_shift_down_(s, 0u, s->p[--s->n]); ELEMENT_INIT(e); return e; } return 0; }
struct event* min_heap_pop(min_heap_t* s) { if (s->n) { struct event* e = *s->p; min_heap_shift_down_(s, 0u, s->p[--s->n]); e->ev_timeout_pos.min_heap_idx = -1; return e; } return 0; }
event_t * min_heap_pop_(min_heap_t *s) { if (s->n) { event_t *e = *s->p; min_heap_shift_down_(s, 0u, s->p[--s->n]); e->min_heap_idx = -1; return e; } else { return 0; } }
int min_heap_erase_(min_heap_t *s, event_t *e) { // if (e->min_heap_idx != -1) { event_t *last = s->p[--s->n]; unsigned parent = (e->min_heap_idx - 1 ) / 2; if (e->min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], last) ) { min_heap_shift_up_unconditional_(s, e->min_heap_idx, last); } else { min_heap_shift_down_(s, e->min_heap_idx, last); } e->min_heap_idx = -1; return 0; }
int min_heap_erase(min_heap_t* s, struct event* e) { if (((unsigned int)-1) != e->ev_timeout_pos.min_heap_idx) { struct event *last = s->p[--s->n]; unsigned parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; /* we replace e with the last element in the heap. We might need to shift it upward if it is less than its parent, or downward if it is greater than one or both its children. Since the children are known to be less than the parent, it can't need to shift both up and down. */ if (e->ev_timeout_pos.min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], last)) min_heap_shift_up_(s, e->ev_timeout_pos.min_heap_idx, last); else min_heap_shift_down_(s, e->ev_timeout_pos.min_heap_idx, last); e->ev_timeout_pos.min_heap_idx = -1; return 0; } return -1; }
/* *Del node */ int min_heap_erase(struct min_heap* s, element* e) { if (-1 != ELEMENT_INDEX(e)) { element *last = s->p[--s->n]; unsigned parent = (ELEMENT_INDEX(e) - 1) / 2; /* we replace e with the last element in the heap. We might need to * shift it upward if it is less than its parent, or downward if it is * greater than one or both its children. Since the children are known * to be less than the parent, it can't need to shift both up and * down. */ if (ELEMENT_INDEX(e) > 0 && min_heap_elem_greater(s->p[parent], last)) min_heap_shift_up_(s, ELEMENT_INDEX(e), last); else min_heap_shift_down_(s, ELEMENT_INDEX(e), last); ELEMENT_SET_INDEX(e, -1); return 0; } return -1; }