diff --git a/src/include/ngspice/cktdefs.h b/src/include/ngspice/cktdefs.h index 2126aff36..d631016cb 100644 --- a/src/include/ngspice/cktdefs.h +++ b/src/include/ngspice/cktdefs.h @@ -30,6 +30,7 @@ #include "ngspice/sen2defs.h" #include "ngspice/pzdefs.h" #include "ngspice/noisedef.h" +#include "ngspice/hash.h" @@ -281,6 +282,8 @@ struct CKTcircuit { contains only linear elements */ unsigned int CKTnoopac:1; /* flag to indicate that OP will not be evaluated during AC simulation */ + + NGHASHPTR DEVnameHash; }; diff --git a/src/spicelib/analysis/cktdest.c b/src/spicelib/analysis/cktdest.c index 4584f90c0..5f441743c 100644 --- a/src/spicelib/analysis/cktdest.c +++ b/src/spicelib/analysis/cktdest.c @@ -74,6 +74,7 @@ CKTdestroy(CKTcircuit *ckt) FREE(ckt->evt); #endif + nghash_free(ckt->DEVnameHash, NULL, NULL); FREE(ckt); return(OK); } diff --git a/src/spicelib/devices/cktcrte.c b/src/spicelib/devices/cktcrte.c index 549287d9c..3f8adce06 100644 --- a/src/spicelib/devices/cktcrte.c +++ b/src/spicelib/devices/cktcrte.c @@ -66,6 +66,8 @@ CKTcrtElt(CKTcircuit *ckt, GENmodel *modPtr, GENinstance **inInstPtr, IFuid name modPtr->GENinstances = instPtr; + nghash_insert(ckt->DEVnameHash, name, instPtr); + if(inInstPtr != NULL) *inInstPtr = instPtr; diff --git a/src/spicelib/devices/cktfinddev.c b/src/spicelib/devices/cktfinddev.c index 19359fe69..4e423cf95 100644 --- a/src/spicelib/devices/cktfinddev.c +++ b/src/spicelib/devices/cktfinddev.c @@ -10,17 +10,6 @@ Author: 1985 Thomas L. Quarles #include "string.h" -static GENinstance * -find_instance(GENinstance *here, IFuid name) -{ - for (; here; here = here->GENnextInstance) - if (here->GENname == name) - return here; - - return NULL; -} - - int CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel *modfast) { @@ -36,8 +25,8 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel * /* we know the model `modfast', but need to find the device instance */ if (modfast) { - here = find_instance(modfast->GENinstances, name); - if (here) { + here = nghash_find(ckt->DEVnameHash, name); + if (here && here->GENmodPtr == modfast) { if (fast) *fast = here; @@ -54,8 +43,8 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel * /* look through all models */ for (mods = ckt->CKThead[*type]; mods ; mods = mods->GENnextModel) { /* and all instances */ - here = find_instance(mods->GENinstances, name); - if (here) { + here = nghash_find(ckt->DEVnameHash, name); + if (here && here->GENmodPtr == mods) { if (fast) *fast = here; return OK; @@ -72,8 +61,8 @@ CKTfndDev(CKTcircuit *ckt, int *type, GENinstance **fast, IFuid name, GENmodel * /* look through all models */ for (mods = ckt->CKThead[*type]; mods; mods = mods->GENnextModel) { /* and all instances */ - here = find_instance(mods->GENinstances, name); - if (here) { + here = nghash_find(ckt->DEVnameHash, name); + if (here && here->GENmodPtr == mods) { if (fast) *fast = here; return OK; diff --git a/src/spicelib/devices/cktinit.c b/src/spicelib/devices/cktinit.c index 3f9c3e71f..8f81c3cbe 100644 --- a/src/spicelib/devices/cktinit.c +++ b/src/spicelib/devices/cktinit.c @@ -90,6 +90,7 @@ CKTinit(CKTcircuit **ckt) /* new circuit to create */ sckt->CKTabsDv = 0.5; sckt->CKTrelDv = 2.0; sckt->CKTvarHertz = 0; + sckt->DEVnameHash = nghash_init_pointer(100); #ifdef XSPICE /* gtri - begin - wbk - allocate/initialize substructs */