MCPcopy Create free account
hub / github.com/ElementsProject/lightning / dijkstra_

Function dijkstra_

common/dijkstra.c:124–270  ·  view source on GitHub ↗

Do Dijkstra: start in this case is the dst node. */

Source from the content-addressed store, hash-verified

122
123/* Do Dijkstra: start in this case is the dst node. */
124const struct dijkstra *
125dijkstra_(const tal_t *ctx,
126 const struct gossmap *map,
127 const struct gossmap_node *start,
128 struct amount_msat amount,
129 double riskfactor,
130 bool (*channel_ok)(const struct gossmap *map,
131 const struct gossmap_chan *c,
132 int dir,
133 struct amount_msat amount,
134 void *arg),
135 u64 (*channel_score)(struct amount_msat fee,
136 struct amount_msat risk,
137 struct amount_msat total,
138 int dir,
139 const struct gossmap_chan *c),
140 void *arg)
141{
142 struct dijkstra *dij;
143 const struct gossmap_node **heap;
144 size_t heapsize;
145 struct gheap_ctx gheap_ctx;
146
147 /* There doesn't seem to be much difference with fanout 2-4. */
148 gheap_ctx.fanout = 2;
149 /* There seems to be a slight decrease if we alter this value. */
150 gheap_ctx.page_chunks = 1;
151 gheap_ctx.item_size = sizeof(*heap);
152 gheap_ctx.less_comparer = less_comparer;
153 gheap_ctx.less_comparer_ctx = NULL;
154 gheap_ctx.item_mover = item_mover;
155
156 dij = tal_arr(ctx, struct dijkstra, gossmap_max_node_idx(map));
157
158 /* Pay no attention to the man behind the curtain! */
159 global_map = map;
160 global_dijkstra = dij;
161
162 /* Wikipedia's article on Dijkstra is excellent:
163 * https://en.wikipedia.org/wiki/Dijkstra's_algorithm
164 * (License https://creativecommons.org/licenses/by-sa/3.0/)
165 *
166 * So I quote here:
167 *
168 * 1. Mark all nodes unvisited. Create a set of all the unvisited
169 * nodes called the unvisited set.
170 *
171 * 2. Assign to every node a tentative distance value: set it to zero
172 * for our initial node and to infinity for all other nodes. Set the
173 * initial node as current.[14]
174 */
175 heap = mkheap(NULL, dij, map, start, amount);
176 heapsize = tal_count(heap);
177
178 /*
179 * 3. For the current node, consider all of its unvisited neighbors
180 * and calculate their tentative distances through the current
181 * node. Compare the newly calculated tentative distance to the

Callers

nothing calls this directly

Calls 10

gossmap_max_node_idxFunction · 0.85
mkheapFunction · 0.85
get_dijkstraFunction · 0.85
gossmap_nth_chanFunction · 0.85
gossmap_nth_nodeFunction · 0.85
amount_msat_feeFunction · 0.85
risk_priceFunction · 0.85
add_overflows_u64Function · 0.85
amount_msat_addFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected