]>
git.proxmox.com Git - mirror_frr.git/blob - lib/graph.h
2 * Graph data structure.
5 * Copyright (C) 2016 Cumulus Networks, Inc.
7 * This file is part of GNU Zebra.
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #ifndef _ZEBRA_COMMAND_GRAPH_H
26 #define _ZEBRA_COMMAND_GRAPH_H
35 vector from
; // nodes which have edges to this node
36 vector to
; // nodes which this node has edges to
38 void *data
; // node data
39 void (*del
)(void *data
); // deletion callback
42 struct graph
*graph_new(void);
47 * @struct graph the graph this node exists in
48 * @param[in] data this node's data
49 * @param[in] del data deletion callback
50 * @return the new node
52 struct graph_node
*graph_new_node(struct graph
*graph
, void *data
,
58 * Before deletion, this function removes all edges to and from this node from
61 * If *data and *del are non-null, the following call is made:
62 * (*node->del) (node->data);
64 * @param[in] graph the graph this node belongs to
65 * @param[out] node pointer to node to delete
67 void graph_delete_node(struct graph
*graph
, struct graph_node
*node
);
70 * Makes a directed edge between two nodes.
76 struct graph_node
*graph_add_edge(struct graph_node
*from
,
77 struct graph_node
*to
);
80 * Removes a directed edge between two nodes.
85 void graph_remove_edge(struct graph_node
*from
, struct graph_node
*to
);
89 * Calls graph_delete_node on each node before freeing the graph struct itself.
91 * @param graph the graph to delete
93 void graph_delete_graph(struct graph
*graph
);
95 #endif /* _ZEBRA_COMMAND_GRAPH_H */