mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
plugins/renepay/dijkstra: improve API to remove global.
The global is an *internal* hack because dijkstra_item_mover doesn't take a context arg! It should be used with care. Easy, since all the accessors exist: we just hand in the struct dijkstra. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -5,45 +5,26 @@
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <gheap.h>
|
||||
|
||||
/* In the heap we keep node idx, but in this structure we keep the distance
|
||||
* value associated to every node, and their position in the heap as a pointer
|
||||
* so that we can update the nodes inside the heap when the distance label is
|
||||
* changed.
|
||||
*
|
||||
* Therefore this is no longer a multipurpose heap, the node_idx must be an
|
||||
* index between 0 and less than max_num_nodes. */
|
||||
struct dijkstra {
|
||||
//
|
||||
s64 *distance;
|
||||
u32 *base;
|
||||
u32 **heapptr;
|
||||
size_t heapsize;
|
||||
struct gheap_ctx gheap_ctx;
|
||||
};
|
||||
|
||||
/* Allocation of resources for the heap. */
|
||||
void dijkstra_malloc(const tal_t *ctx, const size_t max_num_nodes);
|
||||
|
||||
/* Manually release dijkstra resources. */
|
||||
void dijkstra_free(void);
|
||||
struct dijkstra *dijkstra_new(const tal_t *ctx, size_t max_num_nodes);
|
||||
|
||||
/* Initialization of the heap for a new Dijkstra search. */
|
||||
void dijkstra_init(void);
|
||||
void dijkstra_init(struct dijkstra *dijkstra);
|
||||
|
||||
/* Inserts a new element in the heap. If node_idx was already in the heap then
|
||||
* its distance value is updated. */
|
||||
void dijkstra_update(u32 node_idx, s64 distance);
|
||||
void dijkstra_update(struct dijkstra *dijkstra, u32 node_idx, s64 distance);
|
||||
|
||||
u32 dijkstra_top(void);
|
||||
bool dijkstra_empty(void);
|
||||
void dijkstra_pop(void);
|
||||
u32 dijkstra_top(const struct dijkstra *dijkstra);
|
||||
bool dijkstra_empty(const struct dijkstra *dijkstra);
|
||||
void dijkstra_pop(struct dijkstra *dijkstra);
|
||||
|
||||
const s64* dijkstra_distance_data(void);
|
||||
const s64* dijkstra_distance_data(const struct dijkstra *dijkstra);
|
||||
|
||||
/* Number of elements on the heap. */
|
||||
size_t dijkstra_size(void);
|
||||
size_t dijkstra_size(const struct dijkstra *dijkstra);
|
||||
|
||||
/* Maximum number of elements the heap can host */
|
||||
size_t dijkstra_maxsize(void);
|
||||
size_t dijkstra_maxsize(const struct dijkstra *dijkstra);
|
||||
|
||||
#endif /* LIGHTNING_PLUGINS_RENEPAY_DIJKSTRA_H */
|
||||
|
||||
Reference in New Issue
Block a user