]> git.proxmox.com Git - mirror_frr.git/blame - lib/graph.h
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / lib / graph.h
CommitLineData
16d7c050
QY
1/*
2 * Graph data structure.
3 *
4 * --
5 * Copyright (C) 2016 Cumulus Networks, Inc.
6 *
7 * This file is part of GNU Zebra.
8 *
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
12 * later version.
13 *
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.
18 *
896014f4
DL
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16d7c050
QY
22 */
23
24#ifndef _ZEBRA_COMMAND_GRAPH_H
25#define _ZEBRA_COMMAND_GRAPH_H
26
27#include "vector.h"
28
16d7c050
QY
29struct graph
30{
1eb5e8dc
QY
31 vector nodes;
32};
16d7c050 33
16d7c050
QY
34struct graph_node
35{
36 vector from; // nodes which have edges to this node
37 vector to; // nodes which this node has edges to
38
39 void *data; // node data
1eb5e8dc 40 void (*del) (void *data); // deletion callback
16d7c050
QY
41};
42
1eb5e8dc
QY
43struct graph *
44graph_new (void);
45
16d7c050
QY
46/**
47 * Creates a new node.
48 *
49 * @struct graph the graph this node exists in
50 * @param[in] data this node's data
51 * @param[in] del data deletion callback
52 * @return the new node
53 */
54struct graph_node *
55graph_new_node (struct graph *graph, void *data, void (*del) (void*));
56
57/**
58 * Deletes a node.
59 *
60 * Before deletion, this function removes all edges to and from this node from
61 * any neighbor nodes.
62 *
16d7c050
QY
63 * If *data and *del are non-null, the following call is made:
64 * (*node->del) (node->data);
65 *
ba06a3a0 66 * @param[in] graph the graph this node belongs to
16d7c050
QY
67 * @param[out] node pointer to node to delete
68 */
69void
70graph_delete_node (struct graph *graph, struct graph_node *node);
71
72/**
73 * Makes a directed edge between two nodes.
74 *
75 * @param[in] from
76 * @param[in] to
77 * @return to
78 */
79struct graph_node *
80graph_add_edge (struct graph_node *from, struct graph_node *to);
81
82/**
ba06a3a0 83 * Removes a directed edge between two nodes.
16d7c050 84 *
ba06a3a0
QY
85 * @param[in] from
86 * @param[in] to
87 */
88void
89graph_remove_edge (struct graph_node *from, struct graph_node *to);
90
91/**
92 * Deletes a graph.
16d7c050
QY
93 * Calls graph_delete_node on each node before freeing the graph struct itself.
94 *
95 * @param graph the graph to delete
96 */
97void
98graph_delete_graph (struct graph *graph);
99
100#endif /* _ZEBRA_COMMAND_GRAPH_H */