From 7b495e0a7b7170ebfdfadba4411db0a724337c45 Mon Sep 17 00:00:00 2001 From: rlar Date: Wed, 17 Jul 2013 20:36:21 +0200 Subject: [PATCH] CKTfndMod(), use a hashtable --- src/frontend/spiceif.c | 2 ++ src/include/ngspice/cktdefs.h | 1 + src/spicelib/analysis/cktdest.c | 1 + src/spicelib/analysis/cktfndm.c | 27 +-------------------------- src/spicelib/analysis/cktmcrt.c | 1 + src/spicelib/devices/cktinit.c | 1 + 6 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/frontend/spiceif.c b/src/frontend/spiceif.c index e3aa65f60..8d65a82bb 100644 --- a/src/frontend/spiceif.c +++ b/src/frontend/spiceif.c @@ -916,6 +916,8 @@ if_setparam_model(CKTcircuit *ckt, char **name, char *val) INPgetMod(ckt, mods->GENmodName, &inpmod, ft_curckt->ci_symtab); inpmod->INPmodUsed = 0; + if (curMod != nghash_delete(ckt->MODnameHash, curMod->GENmodName)) + fprintf(stderr, "ERROR, ouch nasal daemons ...\n"); FREE(mods); break; diff --git a/src/include/ngspice/cktdefs.h b/src/include/ngspice/cktdefs.h index 6a6aa7f7f..4ce4883ac 100644 --- a/src/include/ngspice/cktdefs.h +++ b/src/include/ngspice/cktdefs.h @@ -284,6 +284,7 @@ struct CKTcircuit { during AC simulation */ NGHASHPTR DEVnameHash; + NGHASHPTR MODnameHash; }; diff --git a/src/spicelib/analysis/cktdest.c b/src/spicelib/analysis/cktdest.c index 5f441743c..fad40d5ea 100644 --- a/src/spicelib/analysis/cktdest.c +++ b/src/spicelib/analysis/cktdest.c @@ -75,6 +75,7 @@ CKTdestroy(CKTcircuit *ckt) #endif nghash_free(ckt->DEVnameHash, NULL, NULL); + nghash_free(ckt->MODnameHash, NULL, NULL); FREE(ckt); return(OK); } diff --git a/src/spicelib/analysis/cktfndm.c b/src/spicelib/analysis/cktfndm.c index 5942ed3c6..a1737ab32 100644 --- a/src/spicelib/analysis/cktfndm.c +++ b/src/spicelib/analysis/cktfndm.c @@ -16,30 +16,5 @@ Author: 1985 Thomas L. Quarles GENmodel * CKTfndMod(CKTcircuit *ckt, int type, GENmodel **modfast, IFuid modname) { - GENmodel *mods; - - if(type >=0 && type < DEVmaxnum) { - /* have device type, need to find model */ - /* look through all models */ - for(mods=ckt->CKThead[type]; mods != NULL ; - mods = mods->GENnextModel) { - if(mods->GENmodName == modname) { - return mods; - } - } - return NULL; - } else if(type == -1) { - /* look through all types (UGH - worst case - take forever) */ - for(type = 0;type CKThead[type];mods!=NULL; - mods = mods->GENnextModel) { - if(mods->GENmodName == modname) { - return mods; - } - } - } - return NULL; - } else return NULL; + return nghash_find(ckt->MODnameHash, modname); } diff --git a/src/spicelib/analysis/cktmcrt.c b/src/spicelib/analysis/cktmcrt.c index e60daa8ad..4fd747c92 100644 --- a/src/spicelib/analysis/cktmcrt.c +++ b/src/spicelib/analysis/cktmcrt.c @@ -33,6 +33,7 @@ CKTmodCrt(CKTcircuit *ckt, int type, GENmodel **modfast, IFuid name) mymodfast->GENnextModel = ckt->CKThead[type]; ckt->CKThead[type] = mymodfast; if(modfast) *modfast=mymodfast; + nghash_insert(ckt->MODnameHash, name, mymodfast); return(OK); } else { if(modfast) *modfast=mymodfast; diff --git a/src/spicelib/devices/cktinit.c b/src/spicelib/devices/cktinit.c index 8f81c3cbe..b415f4fb5 100644 --- a/src/spicelib/devices/cktinit.c +++ b/src/spicelib/devices/cktinit.c @@ -91,6 +91,7 @@ CKTinit(CKTcircuit **ckt) /* new circuit to create */ sckt->CKTrelDv = 2.0; sckt->CKTvarHertz = 0; sckt->DEVnameHash = nghash_init_pointer(100); + sckt->MODnameHash = nghash_init_pointer(100); #ifdef XSPICE /* gtri - begin - wbk - allocate/initialize substructs */