Browse Source

CKTfndDev(), use a hashtable to speed up this function

pre-master-46
Henrik Forstén 13 years ago
committed by rlar
parent
commit
b96be8d576
  1. 3
      src/include/ngspice/cktdefs.h
  2. 1
      src/spicelib/analysis/cktdest.c
  3. 2
      src/spicelib/devices/cktcrte.c
  4. 23
      src/spicelib/devices/cktfinddev.c
  5. 1
      src/spicelib/devices/cktinit.c

3
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;
};

1
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);
}

2
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;

23
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;

1
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 */

Loading…
Cancel
Save