From 2bbadc6085a888e250b8329df38442f761925392 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 17 Nov 2023 13:58:57 +0100 Subject: [PATCH] Use a hash table glonodes to prevent double or multiple entries in global node table global_nodes --- src/frontend/subckt.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index 6de79afd8..f70d463fd 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -61,6 +61,7 @@ Modified: 2000 AlansFixes #include "ngspice/fteinp.h" #include "ngspice/stringskip.h" #include "ngspice/compatmode.h" +#include "ngspice/hash.h" #include @@ -104,6 +105,11 @@ static int inp_numnodes(char c); #define N_GLOBAL_NODES 1005 +/* hash table to store the global nodes + * For now its use is limited to avoid double entries in global_nodes[] */ +static NGHASHPTR glonodes = NULL; +#define DUMMYDATA ((void *)42) + /*--------------------------------------------------------------------- * table is used in settrans and gettrans -- it holds the netnames used * in the .subckt definition (t_old), and in the subcircuit invocation @@ -144,29 +150,40 @@ static int num_global_nodes; static void collect_global_nodes(struct card *c) { + glonodes = nghash_init(NGHASH_MIN_SIZE); + num_global_nodes = 0; global_nodes[num_global_nodes++] = copy("0"); + nghash_insert(glonodes, global_nodes[num_global_nodes - 1], DUMMYDATA); #ifdef XSPICE global_nodes[num_global_nodes++] = copy("null"); + nghash_insert(glonodes, global_nodes[num_global_nodes - 1], DUMMYDATA); #endif + + for (; c; c = c->nextcard) if (ciprefix(".global", c->line)) { char *s = c->line; s = nexttok(s); while (*s) { if (num_global_nodes == N_GLOBAL_NODES) { - fprintf(stderr, "ERROR, N_GLOBAL_NODES overflow\n"); + fprintf(stderr, "ERROR, the number of global nodes is limited to %d\n", N_GLOBAL_NODES); controlled_exit(EXIT_FAILURE); } char *t = skip_non_ws(s); - global_nodes[num_global_nodes++] = copy_substring(s, t); + char *gnode = copy_substring(s, t); + if (nghash_find(glonodes, gnode) == NULL) { + global_nodes[num_global_nodes++] = gnode; + nghash_insert(glonodes, gnode, DUMMYDATA); + } s = skip_ws(t); } c->line[0] = '*'; /* comment it out */ } + nghash_free(glonodes, NULL, NULL); #ifdef TRACE {