Remove global edge_tree.

This commit is contained in:
Guus Sliepen 2002-09-06 10:23:52 +00:00
parent 641705df90
commit fbf8a47879
3 changed files with 19 additions and 38 deletions

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: edge.c,v 1.1.2.12 2002/09/04 13:48:51 guus Exp $ $Id: edge.c,v 1.1.2.13 2002/09/06 10:23:52 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -41,32 +41,13 @@
#include "xalloc.h" #include "xalloc.h"
#include "system.h" #include "system.h"
avl_tree_t *edge_tree; /* Tree with all known edges (replaces active_tree) */
avl_tree_t *edge_weight_tree; /* Tree with all edges, sorted on weight */ avl_tree_t *edge_weight_tree; /* Tree with all edges, sorted on weight */
int edge_compare(edge_t *a, edge_t *b) int edge_compare(edge_t *a, edge_t *b)
{ {
int result; return strcmp(a->to->name, b->to->name);
result = strcmp(a->from->name, b->from->name);
if(result)
return result;
else
return strcmp(a->to->name, b->to->name);
} }
/* Evil edge_compare() from a parallel universe ;)
int edge_compare(edge_t *a, edge_t *b)
{
int result;
return (result = strcmp(a->from->name, b->from->name)) || (result = strcmp(a->to->name, b->to->name)), result;
}
*/
int edge_weight_compare(edge_t *a, edge_t *b) int edge_weight_compare(edge_t *a, edge_t *b)
{ {
int result; int result;
@ -82,7 +63,6 @@ int edge_weight_compare(edge_t *a, edge_t *b)
void init_edges(void) void init_edges(void)
{ {
cp cp
edge_tree = avl_alloc_tree((avl_compare_t)edge_compare, NULL);
edge_weight_tree = avl_alloc_tree((avl_compare_t)edge_weight_compare, NULL); edge_weight_tree = avl_alloc_tree((avl_compare_t)edge_weight_compare, NULL);
cp cp
} }
@ -104,7 +84,7 @@ cp
void exit_edges(void) void exit_edges(void)
{ {
cp cp
avl_delete_tree(edge_tree); avl_delete_tree(edge_weight_tree);
cp cp
} }
@ -129,7 +109,6 @@ cp
void edge_add(edge_t *e) void edge_add(edge_t *e)
{ {
cp cp
avl_insert(edge_tree, e);
avl_insert(edge_weight_tree, e); avl_insert(edge_weight_tree, e);
avl_insert(e->from->edge_tree, e); avl_insert(e->from->edge_tree, e);
cp cp
@ -145,7 +124,6 @@ cp
if(e->reverse) if(e->reverse)
e->reverse->reverse = NULL; e->reverse->reverse = NULL;
cp cp
avl_delete(edge_tree, e);
avl_delete(edge_weight_tree, e); avl_delete(edge_weight_tree, e);
avl_delete(e->from->edge_tree, e); avl_delete(e->from->edge_tree, e);
cp cp
@ -158,25 +136,30 @@ cp
v.from = from; v.from = from;
v.to = to; v.to = to;
return avl_search(edge_tree, &v); return avl_search(from->edge_tree, &v);
} }
void dump_edges(void) void dump_edges(void)
{ {
avl_node_t *node; avl_node_t *node, *node2;
node_t *n;
edge_t *e; edge_t *e;
char *address; char *address;
cp cp
syslog(LOG_DEBUG, _("Edges:")); syslog(LOG_DEBUG, _("Edges:"));
for(node = edge_tree->head; node; node = node->next) for(node = node_tree->head; node; node = node->next)
{ {
e = (edge_t *)node->data; n = (node_t *)node->data;
address = sockaddr2hostname(&e->address); for(node2 = n->edge_tree->head; node2; node2 = node2->next)
syslog(LOG_DEBUG, _(" %s to %s at %s options %lx weight %d"), {
e->from->name, e->to->name, address, e = (edge_t *)node2->data;
e->options, e->weight); address = sockaddr2hostname(&e->address);
free(address); syslog(LOG_DEBUG, _(" %s to %s at %s options %lx weight %d"),
e->from->name, e->to->name, address,
e->options, e->weight);
free(address);
}
} }
syslog(LOG_DEBUG, _("End of edges.")); syslog(LOG_DEBUG, _("End of edges."));

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: edge.h,v 1.1.2.9 2002/09/04 13:48:51 guus Exp $ $Id: edge.h,v 1.1.2.10 2002/09/06 10:23:52 guus Exp $
*/ */
#ifndef __TINC_EDGE_H__ #ifndef __TINC_EDGE_H__
@ -41,7 +41,6 @@ typedef struct edge_t {
struct edge_t *reverse; /* edge in the opposite direction, if available */ struct edge_t *reverse; /* edge in the opposite direction, if available */
} edge_t; } edge_t;
extern avl_tree_t *edge_tree; /* Tree with all known edges */
extern avl_tree_t *edge_weight_tree; /* Tree with all known edges sorted on weight */ extern avl_tree_t *edge_weight_tree; /* Tree with all known edges sorted on weight */
extern void init_edges(void); extern void init_edges(void);

View file

@ -17,7 +17,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: net_packet.c,v 1.1.2.19 2002/09/04 13:48:52 guus Exp $ $Id: net_packet.c,v 1.1.2.20 2002/09/06 10:23:52 guus Exp $
*/ */
#include "config.h" #include "config.h"
@ -429,4 +429,3 @@ cp
receive_udppacket(n, &pkt); receive_udppacket(n, &pkt);
cp cp
} }