From: David Given Date: Fri, 16 Dec 2016 23:21:27 +0000 (+0100) Subject: Massive graph performance boost by checking to see whether an edge already X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=02678ba9d38deb77d1c8fdea7414b3294b42d02c;p=ack.git Massive graph performance boost by checking to see whether an edge already exists in the hash table before trying to add it. --- diff --git a/modules/src/data/bigraph.c b/modules/src/data/bigraph.c index 1e6a84151..4499563d6 100644 --- a/modules/src/data/bigraph.c +++ b/modules/src/data/bigraph.c @@ -130,10 +130,16 @@ void graph_add_edge(struct graph* g, void* data1, void* data2) struct vertex* v1 = find_or_add_vertex(g, data1); struct vertex* v2 = find_or_add_vertex(g, data2); struct edgenode* e; + struct edgenode template; if (v1 == v2) return; + template.this = v1; + template.other = v2; + if (hashtable_contains(&g->edges, &template)) + return; + add_edge(v1, v2); e = add_edge(v2, v1);