void ajCallRegisterOld(const char *name, CallFunc func) { void *rec; char* keyname = NULL; ajuint *i; if(!oldcallTable) { oldcallTable = ajTableNewFunctionLen(50, callCmpStr,callStrHash); oldcallCount = ajTableNewFunctionLen(50, callCmpStr,callStrHash); } rec = ajTableFetch(oldcallTable, name); /* does it exist already */ if(!rec) { keyname = ajCharNewC(name); ajTablePut(oldcallTable, keyname, (void *) func); keyname = ajCharNewC(name); AJNEW0(i); ajTablePut(oldcallCount, keyname, i); } return; }
void ajCallRegister(const char *name, CallFunc func) { void *rec; char* keyname = NULL; if(!callTable) callTable = ajTableNewFunctionLen(50, callCmpStr,callStrHash); rec = ajTableFetch(callTable, name); /* does it exist already */ if(!rec) { keyname = ajCharNewC(name); ajTablePut(callTable, keyname, (void *) func); } return; }
EnsPCache ensCacheNew(AjEnum type, ajuint maxbytes, ajuint maxcount, ajuint maxsize, void* Freference(void* value), void Fdelete(void** value), ajuint Fsize(const void* value), void* Fread(const void* key), AjBool Fwrite(const void* value), AjBool synchron, const char *label) { AjBool debug = AJFALSE; EnsPCache cache = NULL; debug = ajDebugTest("ensCacheNew"); if(debug) ajDebug("ensCacheNew\n" " type %d\n" " maxbytes %u\n" " maxcount %u\n" " maxsize %u\n" " Freference %p\n" " Fdelete %p\n" " Fsize %p\n" " Fread %p\n" " Fwrite %p\n" " synchron '%B'\n" " label '%s'\n", type, maxbytes, maxcount, maxsize, Freference, Fdelete, Fsize, Fread, Fwrite, synchron, label); if((type < ensECacheTypeNumeric) || (type > ensECacheTypeAlphaNumeric)) ajFatal("ensCacheNew requires a valid type.\n"); if((!maxbytes) && (!maxcount)) ajFatal("ensCacheNew requires either a " "maximum bytes or maximum count limit.\n"); if(!maxsize) maxsize = maxbytes ? maxbytes / 10 + 1 : 0; if(maxbytes && (!maxsize)) ajFatal("ensCacheNew requires a maximum size limit, " "when a maximum bytes limit is set."); /* TODO: Find and set a sensible value here! */ if(debug) ajDebug("ensCacheNew maxbytes %u, maxcount %u, maxsize %u.\n", maxbytes, maxcount, maxsize); if(maxbytes && (maxbytes < 1000)) ajFatal("ensCacheNew cannot set a maximum bytes limit (%u) under " "1000, as each Cache Node requires %u bytes alone.", maxbytes, sizeof(CachePNode)); /* TODO: Find and set a sensible value here! */ if(maxsize && (maxsize < 3)) ajFatal("ensCacheNew cannot set a maximum size limit (%u) under " "3 bytes. maximum bytes %u maximum count %u.", maxsize, maxbytes, maxcount); /* ** Pointers to functions for automatic reading of data not yet in the ** cache and writing of data modified in cache are not mandatory. ** If not specified the cache will simply lack this functionality. ** However, the specification of a function deleting stale cache entries ** and a function calculating the size of value data are required. */ if(!(void*)Freference) ajFatal("ensCacheNew requires a referencing function."); if(!(void*)Fdelete) ajFatal("ensCacheNew requires a deletion function."); if(maxsize && (!(void*)Fsize)) ajFatal("ensCacheNew requires a memory sizing function " "when a maximum size limit has been defined."); if(!label) ajFatal("ensCacheNew requires a label."); AJNEW0(cache); cache->Label = ajStrNewC(label); cache->List = ajListNew(); switch(type) { case ensECacheTypeNumeric: cache->Table = ajTableNewFunctionLen(0, ensTableCmpUint, ensTableHashUint); break; case ensECacheTypeAlphaNumeric: cache->Table = ajTablestrNewLen(0); break; default: ajWarn("ensCacheNew got unexpected Cache type %d.\n", cache->Type); } cache->Reference = Freference; cache->Delete = Fdelete; cache->Size = Fsize; cache->Read = Fread; cache->Write = Fwrite; cache->Type = type; cache->Synchron = synchron; cache->MaxBytes = maxbytes; cache->MaxCount = maxcount; cache->MaxSize = maxsize; cache->Bytes = 0; cache->Count = 0; cache->Dropped = 0; cache->Removed = 0; cache->Stored = 0; cache->Hit = 0; cache->Miss = 0; return cache; }
AjPTable ajCallTableNew(void) { return ajTableNewFunctionLen(50, callCmpStr,callStrHash); }
static AjBool assemblyexceptionadaptorCacheInit( EnsPAssemblyexceptionadaptor aea) { ajuint *Pidentifier = NULL; AjPList list = NULL; AjPList aes = NULL; AjPStr statement = NULL; EnsPAssemblyexception ae = NULL; if(!aea) return ajFalse; if(aea->CacheBySeqregionIdentifier) return ajTrue; else aea->CacheBySeqregionIdentifier = ajTableNewFunctionLen(0, ensTableCmpUint, ensTableHashUint); statement = ajFmtStr( "SELECT " "assembly_exception.assembly_exception_id, " "assembly_exception.seq_region_id, " "assembly_exception.seq_region_start, " "assembly_exception.seq_region_end, " "assembly_exception.exc_type, " "assembly_exception.exc_seq_region_id, " "assembly_exception.exc_seq_region_start, " "assembly_exception.exc_seq_region_end, " "assembly_exception.ori " "FROM " "assembly_exception, " "seq_region, " "coord_system " "WHERE " "seq_region.seq_region_id = " "assembly_exception.seq_region_id " "AND " "seq_region.coord_system_id = " "coord_system.coord_system_id " "AND " "coord_system.species_id = %u", ensDatabaseadaptorGetIdentifier(aea->Adaptor)); aes = ajListNew(); assemblyexceptionadaptorFetchAllBySQL(aea, statement, aes); ajStrDel(&statement); while(ajListPop(aes, (void **) &ae)) { list = (AjPList) ajTableFetch(aea->CacheBySeqregionIdentifier, (const void *) &ae->SeqregionIdentifier); if(!list) { AJNEW0(Pidentifier); *Pidentifier = ae->SeqregionIdentifier; list = ajListNew(); ajTablePut(aea->CacheBySeqregionIdentifier, (void *) Pidentifier, (void *) list); } ajListPushAppend(list, (void *) ae); } ajListFree(&aes); return ajTrue; }