Re: [PATCH v3 02/10] lib: introduce generic min max heap

From: Peter Zijlstra
Date: Thu Nov 14 2019 - 04:35:31 EST


On Wed, Nov 13, 2019 at 04:30:34PM -0800, Ian Rogers wrote:
> +/*
> + * Remove the minimum element and then push the given element. The
> + * implementation performs 1 sift (O(log2(size))) and is therefore more
> + * efficient than a pop followed by a push that does 2.
> + */
> +static void heap_pop_push(struct min_max_heap *heap,
> + const void *element,
> + const struct min_max_heap_callbacks *func)
> +{
> + char *data = (char *)heap->data;
> +
> + memcpy(data, element, func->elem_size);
> + heapify(heap, 0, func);
> +}

I'm not a fan of this operation. It has a weird name and it is utterly
trivial.