Typedefs | |
typedef piojo_id_t | piojo_graph_vid_t |
typedef float | piojo_graph_weight_t |
typedef bool(* | piojo_graph_visit_cb )(piojo_graph_vid_t v, const piojo_graph_t *graph) |
typedef piojo_graph_weight_t(* | piojo_graph_cost_cb )(piojo_graph_vid_t from, piojo_graph_vid_t to, const piojo_graph_t *graph) |
Enumerations | |
enum | piojo_graph_dir_t { PIOJO_GRAPH_DIR_TRUE, PIOJO_GRAPH_DIR_FALSE } |
Functions | |
piojo_graph_t * | piojo_graph_alloc (piojo_graph_dir_t directed) |
piojo_graph_t * | piojo_graph_alloc_cb (piojo_graph_dir_t directed, piojo_alloc_if allocator) |
piojo_graph_t * | piojo_graph_copy (const piojo_graph_t *graph) |
void | piojo_graph_free (const piojo_graph_t *graph) |
void | piojo_graph_clear (piojo_graph_t *graph) |
void | piojo_graph_set_gvalue (piojo_opaque_t value, piojo_graph_t *graph) |
piojo_opaque_t | piojo_graph_gvalue (const piojo_graph_t *graph) |
bool | piojo_graph_insert (piojo_graph_vid_t vertex, piojo_graph_t *graph) |
bool | piojo_graph_delete (piojo_graph_vid_t vertex, piojo_graph_t *graph) |
void | piojo_graph_set_vvalue (piojo_opaque_t value, piojo_graph_vid_t vertex, piojo_graph_t *graph) |
piojo_opaque_t | piojo_graph_vvalue (piojo_graph_vid_t vertex, const piojo_graph_t *graph) |
void | piojo_graph_link (piojo_graph_weight_t weight, piojo_graph_vid_t from, piojo_graph_vid_t to, piojo_graph_t *graph) |
piojo_graph_weight_t * | piojo_graph_linked (piojo_graph_vid_t from, piojo_graph_vid_t to, const piojo_graph_t *graph) |
void | piojo_graph_unlink (piojo_graph_vid_t from, piojo_graph_vid_t to, piojo_graph_t *graph) |
void | piojo_graph_unlink_all (piojo_graph_vid_t vertex, piojo_graph_t *graph) |
size_t | piojo_graph_neighbor_cnt (piojo_graph_vid_t vertex, const piojo_graph_t *graph) |
piojo_graph_vid_t | piojo_graph_neighbor_at (size_t idx, piojo_graph_vid_t vertex, const piojo_graph_t *graph) |
piojo_graph_weight_t | piojo_graph_edge_weight (size_t idx, piojo_graph_vid_t vertex, const piojo_graph_t *graph) |
bool | piojo_graph_vid_eq (const void *e1, const void *e2) |
bool | piojo_graph_breadth_first (piojo_graph_vid_t root, piojo_graph_visit_cb cb, size_t limit, const piojo_graph_t *graph) |
bool | piojo_graph_depth_first (piojo_graph_vid_t root, piojo_graph_visit_cb cb, size_t limit, const piojo_graph_t *graph) |
void | piojo_graph_source_path (piojo_graph_vid_t root, const piojo_graph_t *graph, piojo_hash_t *dists, piojo_hash_t *prevs) |
piojo_graph_weight_t | piojo_graph_pair_path (piojo_graph_vid_t root, piojo_graph_vid_t dst, const piojo_graph_t *graph, piojo_hash_t *prevs) |
bool | piojo_graph_neg_source_path (piojo_graph_vid_t root, const piojo_graph_t *graph, piojo_hash_t *dists, piojo_hash_t *prevs) |
piojo_graph_weight_t | piojo_graph_min_tree (const piojo_graph_t *graph, piojo_graph_t *tree) |
piojo_graph_weight_t | piojo_graph_a_star (piojo_graph_vid_t root, piojo_graph_vid_t dst, piojo_graph_cost_cb heuristic, const piojo_graph_t *graph, piojo_hash_t *prevs) |
bool | piojo_graph_sort (const piojo_graph_t *graph, piojo_array_t *vertices) |
Variables | |
const size_t | piojo_graph_sizeof |
const piojo_graph_weight_t | PIOJO_GRAPH_WEIGHT_MAX |
Piojo Graph implementation.
typedef piojo_graph_weight_t(* piojo_graph_cost_cb)(piojo_graph_vid_t from, piojo_graph_vid_t to, const piojo_graph_t *graph) |
Returns cost estimate between two vertices.
typedef piojo_id_t piojo_graph_vid_t |
Vertex id.
typedef bool(* piojo_graph_visit_cb)(piojo_graph_vid_t v, const piojo_graph_t *graph) |
Vertex visitor, returns TRUE to stop traversal, FALSE otherwise.
typedef float piojo_graph_weight_t |
Edge weight.
enum piojo_graph_dir_t |
piojo_graph_weight_t piojo_graph_a_star | ( | piojo_graph_vid_t | root, |
piojo_graph_vid_t | dst, | ||
piojo_graph_cost_cb | heuristic, | ||
const piojo_graph_t * | graph, | ||
piojo_hash_t * | prevs | ||
) |
Finds shortest path from root to dst vertex using A* algorithm.
[in] | root | Starting vertex. |
[in] | dst | Destination vertex. |
[in] | heuristic | Cost estimate function (should be consistent). |
[in] | graph | |
[out] | prevs | Previous vertex in path for each vertex (if a path exists), can be NULL. |
piojo_graph_t* piojo_graph_alloc | ( | piojo_graph_dir_t | directed | ) |
Allocates a new graph. Uses default allocator.
[in] | directed | Graph direction. |
piojo_graph_t* piojo_graph_alloc_cb | ( | piojo_graph_dir_t | directed, |
piojo_alloc_if | allocator | ||
) |
Allocates a new graph.
[in] | directed | Graph direction. |
[in] | allocator | Allocator to be used. |
bool piojo_graph_breadth_first | ( | piojo_graph_vid_t | root, |
piojo_graph_visit_cb | cb, | ||
size_t | limit, | ||
const piojo_graph_t * | graph | ||
) |
Traverses graph following a breadth first search.
[in] | root | Starting vertex. |
[in] | cb | Vertex visit function. |
[in] | limit | Depth limit or 0 for no limit. |
[in] | graph |
void piojo_graph_clear | ( | piojo_graph_t * | graph | ) |
Deletes all vertices/edges in graph.
[out] | graph | Graph being cleared. |
piojo_graph_t* piojo_graph_copy | ( | const piojo_graph_t * | graph | ) |
Copies graph and all its vertices/edges.
[in] | graph | Graph being copied. |
bool piojo_graph_delete | ( | piojo_graph_vid_t | vertex, |
piojo_graph_t * | graph | ||
) |
Deletes vertex.
[in] | vertex | Vertex being deleted. |
[out] | graph |
bool piojo_graph_depth_first | ( | piojo_graph_vid_t | root, |
piojo_graph_visit_cb | cb, | ||
size_t | limit, | ||
const piojo_graph_t * | graph | ||
) |
Traverses graph following a depth first search.
[in] | root | Starting vertex. |
[in] | cb | Vertex visit function. |
[in] | limit | Depth limit or 0 for no limit. |
[in] | graph |
piojo_graph_weight_t piojo_graph_edge_weight | ( | size_t | idx, |
piojo_graph_vid_t | vertex, | ||
const piojo_graph_t * | graph | ||
) |
Returns edge weight from vertex to neighbor idx.
[in] | idx | Neighbor index. |
[in] | vertex | Vertex. |
[in] | graph |
void piojo_graph_free | ( | const piojo_graph_t * | graph | ) |
Frees graph and all its vertices/edges.
[in] | graph | Graph being freed. |
piojo_opaque_t piojo_graph_gvalue | ( | const piojo_graph_t * | graph | ) |
Returns user-defined graph value (default is 0).
[in] | graph |
bool piojo_graph_insert | ( | piojo_graph_vid_t | vertex, |
piojo_graph_t * | graph | ||
) |
Inserts new vertex.
[in] | vertex | |
[out] | graph |
void piojo_graph_link | ( | piojo_graph_weight_t | weight, |
piojo_graph_vid_t | from, | ||
piojo_graph_vid_t | to, | ||
piojo_graph_t * | graph | ||
) |
Links two vertices, if they're already linked updates the weight.
[in] | weight | Edge weight. |
[in] | from | Source vertex. |
[in] | to | Destination vertex. |
[out] | graph |
piojo_graph_weight_t* piojo_graph_linked | ( | piojo_graph_vid_t | from, |
piojo_graph_vid_t | to, | ||
const piojo_graph_t * | graph | ||
) |
Returns edge weight if an edge exists between two vertices.
[in] | from | Source vertex. |
[in] | to | Destination vertex. |
[in] | graph |
piojo_graph_weight_t piojo_graph_min_tree | ( | const piojo_graph_t * | graph, |
piojo_graph_t * | tree | ||
) |
Finds minimum spanning tree when graph is connected. Otherwise, finds the minimum spanning forest (Kruskal's algorithm).
[in] | graph | |
[out] | tree | Minimum spanning tree/forest of graph. |
bool piojo_graph_neg_source_path | ( | piojo_graph_vid_t | root, |
const piojo_graph_t * | graph, | ||
piojo_hash_t * | dists, | ||
piojo_hash_t * | prevs | ||
) |
Finds shortest path from root to all vertices (Bellman-Ford algorithm).
[in] | root | Starting vertex. |
[in] | graph | |
[out] | dists | Distance (weight sum) for each vertex (if a path exists). |
[out] | prevs | Previous vertex in path for each vertex (if a path exists), can be NULL. |
piojo_graph_vid_t piojo_graph_neighbor_at | ( | size_t | idx, |
piojo_graph_vid_t | vertex, | ||
const piojo_graph_t * | graph | ||
) |
Returns neighbor from vertex.
[in] | idx | Neighbor index. |
[in] | vertex | Vertex. |
[in] | graph |
size_t piojo_graph_neighbor_cnt | ( | piojo_graph_vid_t | vertex, |
const piojo_graph_t * | graph | ||
) |
Returns neighbor count from vertex.
[in] | vertex | Vertex. |
[in] | graph |
piojo_graph_weight_t piojo_graph_pair_path | ( | piojo_graph_vid_t | root, |
piojo_graph_vid_t | dst, | ||
const piojo_graph_t * | graph, | ||
piojo_hash_t * | prevs | ||
) |
Finds shortest path from root to dst vertex (Dijkstra's algorithm).
[in] | root | Starting vertex. |
[in] | dst | Destination vertex. |
[in] | graph | |
[out] | prevs | Previous vertex in path for each vertex (if a path exists), can be NULL. |
void piojo_graph_set_gvalue | ( | piojo_opaque_t | value, |
piojo_graph_t * | graph | ||
) |
Sets user-defined graph value (default is 0).
[in] | value | |
[out] | graph |
void piojo_graph_set_vvalue | ( | piojo_opaque_t | value, |
piojo_graph_vid_t | vertex, | ||
piojo_graph_t * | graph | ||
) |
Sets user-defined vertex value (default is 0).
[in] | value | |
[in] | vertex | |
[out] | graph |
bool piojo_graph_sort | ( | const piojo_graph_t * | graph, |
piojo_array_t * | vertices | ||
) |
Finds a topological ordering (Kahn's algorithm).
[in] | graph | |
[out] | vertices | Vertices in topological order. |
void piojo_graph_source_path | ( | piojo_graph_vid_t | root, |
const piojo_graph_t * | graph, | ||
piojo_hash_t * | dists, | ||
piojo_hash_t * | prevs | ||
) |
Finds shortest path from root to all vertices (Dijkstra's algorithm).
[in] | root | Starting vertex. |
[in] | graph | |
[out] | dists | Distance (weight sum) for each vertex (if a path exists). |
[out] | prevs | Previous vertex in path for each vertex (if a path exists), can be NULL. |
void piojo_graph_unlink | ( | piojo_graph_vid_t | from, |
piojo_graph_vid_t | to, | ||
piojo_graph_t * | graph | ||
) |
Unlinks two vertices if they are linked (does nothing otherwise).
[in] | from | Vertex. |
[in] | to | Vertex. |
[out] | graph |
void piojo_graph_unlink_all | ( | piojo_graph_vid_t | vertex, |
piojo_graph_t * | graph | ||
) |
Unlinks every vertex from vertex.
[in] | vertex | Vertex. |
[out] | graph |
bool piojo_graph_vid_eq | ( | const void * | e1, |
const void * | e2 | ||
) |
Vertex equality function.
[in] | e1 | Vertex pointer. |
[in] | e2 | Vertex pointer. |
piojo_opaque_t piojo_graph_vvalue | ( | piojo_graph_vid_t | vertex, |
const piojo_graph_t * | graph | ||
) |
Returns user-defined vertex value (default is 0).
[in] | vertex | |
[in] | graph |
const size_t piojo_graph_sizeof |
Size of graph in bytes
const piojo_graph_weight_t PIOJO_GRAPH_WEIGHT_MAX |
Maximum weight, greater values will be capped to it.