2022-02-10 23:07:11 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2018-11-06 02:52:34 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
|
|
|
* \brief A min-heap / priority queue ADT
|
2018-11-06 02:52:34 +01:00
|
|
|
*/
|
|
|
|
|
2020-03-02 15:04:53 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-11-06 03:01:18 +01:00
|
|
|
struct HeapSimple;
|
|
|
|
typedef struct HeapSimple HeapSimple;
|
2018-11-06 02:52:34 +01:00
|
|
|
|
|
|
|
typedef void (*HeapSimpleFreeFP)(void *ptr);
|
|
|
|
|
2021-12-09 10:01:44 +01:00
|
|
|
/**
|
|
|
|
* Creates a new simple heap, which only supports insertion and removal from top.
|
|
|
|
*
|
|
|
|
* \note Use when the size of the heap is known in advance.
|
|
|
|
*/
|
2022-03-30 08:26:42 +02:00
|
|
|
HeapSimple *BLI_heapsimple_new_ex(unsigned int reserve_num) ATTR_WARN_UNUSED_RESULT;
|
2018-11-06 03:01:18 +01:00
|
|
|
HeapSimple *BLI_heapsimple_new(void) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
void BLI_heapsimple_clear(HeapSimple *heap, HeapSimpleFreeFP ptrfreefp) ATTR_NONNULL(1);
|
|
|
|
void BLI_heapsimple_free(HeapSimple *heap, HeapSimpleFreeFP ptrfreefp) ATTR_NONNULL(1);
|
2021-12-09 10:01:44 +01:00
|
|
|
/**
|
|
|
|
* Insert heap node with a value (often a 'cost') and pointer into the heap,
|
|
|
|
* duplicate values are allowed.
|
|
|
|
*/
|
2018-11-06 03:01:18 +01:00
|
|
|
void BLI_heapsimple_insert(HeapSimple *heap, float value, void *ptr) ATTR_NONNULL(1);
|
|
|
|
bool BLI_heapsimple_is_empty(const HeapSimple *heap) ATTR_NONNULL(1);
|
|
|
|
uint BLI_heapsimple_len(const HeapSimple *heap) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 10:01:44 +01:00
|
|
|
/**
|
|
|
|
* Return the lowest value of the heap.
|
|
|
|
*/
|
2018-11-06 03:01:18 +01:00
|
|
|
float BLI_heapsimple_top_value(const HeapSimple *heap) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 10:01:44 +01:00
|
|
|
/**
|
|
|
|
* Pop the top node off the heap and return its pointer.
|
|
|
|
*/
|
2018-11-06 03:01:18 +01:00
|
|
|
void *BLI_heapsimple_pop_min(HeapSimple *heap) ATTR_NONNULL(1);
|
2018-11-06 02:52:34 +01:00
|
|
|
|
2020-03-02 15:04:53 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|