HW04
Source codes for forth assignment
|
Interface for creating graph. More...
#include <stdio.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | edge |
Representation of an edge. More... | |
Typedefs | |
typedef struct node | Node |
Node is an opaque type. More... | |
typedef struct graph | Graph |
Graph is an opaque type. More... | |
Functions | |
unsigned int | node_get_id (Node *n) |
Get id of a node. More... | |
unsigned short | node_get_n_outgoing (Node *n) |
Get number of outgoing edges from a node. More... | |
struct edge * | node_get_edges (Node *n) |
Get array of outgoing edges. More... | |
unsigned int | node_get_distance (Node *n) |
Get distance of this node from starting node. More... | |
Node * | node_get_previous (Node *n) |
Get node on (already found) shortest path from which queried node was visited. More... | |
Graph * | graph_new (void) |
Create a new graph. More... | |
bool | graph_insert_node (Graph *g, unsigned int id) |
Insert node into the graph. More... | |
bool | graph_insert_edge (Graph *g, unsigned int source, unsigned int dest, int mindelay) |
Insert an edge into the graph. More... | |
Node * | graph_get_node (Graph *g, unsigned int id) |
Retrieve a node. More... | |
void | graph_free (Graph *g) |
Free memory used by nodes and edges. More... | |
Interface for creating graph.
This file declares functions and types for creating graphs.
Definition in file graph.h.
typedef struct graph Graph |
typedef struct node Node |
void graph_free | ( | Graph * | g | ) |
Retrieve a node.
This function performs binary search, therefore needs the nodes to be sorted. Sorting is done automatically if necessary. Inserting a node will break the sorted property, so first node retrieval after insertion is going to be slow.
g | graph to be searched |
id | identifier of the node |
bool graph_insert_edge | ( | Graph * | g, |
unsigned int | source, | ||
unsigned int | dest, | ||
int | mindelay | ||
) |
Insert an edge into the graph.
Both nodes need to be present in the graph, otherwise the function will fail. Other reason of failure is malloc failure.
g | graph to insert into |
source | starting node of the edge |
dest | ending node of the edge |
mindelay | minimum delay on this edge |
bool graph_insert_node | ( | Graph * | g, |
unsigned int | id | ||
) |
Graph* graph_new | ( | void | ) |
unsigned int node_get_distance | ( | Node * | n | ) |
Get array of outgoing edges.
The number of elements in this array is returned by node_get_n_outgoing().
n | node to query |
unsigned int node_get_id | ( | Node * | n | ) |
unsigned short node_get_n_outgoing | ( | Node * | n | ) |