CKTfndMod(), use a hashtable

This commit is contained in:
rlar 2013-07-17 20:36:21 +02:00
parent 59309e196b
commit 7b495e0a7b
6 changed files with 7 additions and 26 deletions

View File

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

View File

@ -284,6 +284,7 @@ struct CKTcircuit {
during AC simulation */
NGHASHPTR DEVnameHash;
NGHASHPTR MODnameHash;
};

View File

@ -75,6 +75,7 @@ CKTdestroy(CKTcircuit *ckt)
#endif
nghash_free(ckt->DEVnameHash, NULL, NULL);
nghash_free(ckt->MODnameHash, NULL, NULL);
FREE(ckt);
return(OK);
}

View File

@ -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 <DEVmaxnum;(type)++) {
/* need to find model & device */
/* look through all models */
for(mods=ckt->CKThead[type];mods!=NULL;
mods = mods->GENnextModel) {
if(mods->GENmodName == modname) {
return mods;
}
}
}
return NULL;
} else return NULL;
return nghash_find(ckt->MODnameHash, modname);
}

View File

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

View File

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