2 edge.c -- edge tree management
3 Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
4 2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: edge.c,v 1.1.2.1 2001/10/28 08:41:19 guus Exp $
32 #include "net.h" /* Don't ask. */
42 avl_tree_t *edge_tree; /* Tree with all known vertices (replaces active_tree) */
44 int edge_compare(edge_t *a, edge_t *b)
48 result = strcmp(a->from->name, b->from->name);
53 return strcmp(a->to->name, b->to->name);
56 /* Evil edge_compare() from a parallel universe ;)
58 int edge_compare(edge_t *a, edge_t *b)
62 return (result = strcmp(a->from->name, b->from->name)) || (result = strcmp(a->to->name, b->to->name)), result;
67 void init_vertices(void)
70 edge_tree = avl_alloc_tree((avl_compare_t)edge_compare, NULL);
74 void exit_vertices(void)
77 avl_delete_tree(edge_tree);
81 /* Creation and deletion of connection elements */
83 edge_t *new_edge(void)
86 edge_t *v = (edge_t *)xmalloc_and_zero(sizeof(*v));
91 void free_edge(edge_t *v)
98 void edge_add(edge_t *v)
101 avl_insert(edge_tree, v);
105 void edge_del(edge_t *v)
108 avl_delete(edge_tree, v);
112 edge_t *lookup_edge(node_t *from, node_t *to)
119 result = avl_search(edge_tree, &v);
127 return avl_search(edge_tree, &v);
130 void dump_vertices(void)
135 syslog(LOG_DEBUG, _("Vertices:"));
137 for(node = edge_tree->head; node; node = node->next)
139 v = (edge_t *)node->data;
140 syslog(LOG_DEBUG, _(" %s - %s options %ld"),
141 v->from->name, v->to->name, v->options);
144 syslog(LOG_DEBUG, _("End of vertices."));