30
30
* Version Creation Date: 9/94
34
34
* File Description: Manager for Bioseqs and BioseqSets
37
37
* --------------------------------------------------------------------------
38
* Date Name Description of modification
39
* ------- ---------- -----------------------------------------------------
42
38
* $Log: objmgr.c,v $
39
* Revision 6.57 2004/10/15 19:08:36 bollin
40
* when removing an object, make sure to also deselect it
42
* Revision 6.56 2004/09/07 14:08:27 kans
43
* post errors on failure of ObjMgrNextAvailEntityID and ObjMgrRecycleEntityID
45
* Revision 6.55 2004/06/09 01:56:43 kans
46
* initialize assigned id array from all functions that use it
48
* Revision 6.54 2004/06/08 20:48:09 kans
49
* changed entityID recycling from small array of integers to bit array of all possible values
51
* Revision 6.53 2004/06/08 18:19:01 kans
52
* ObjMgrFreeCacheFunc frees all TL_CACHED, and frees TL_LOADED if type == 0
54
* Revision 6.52 2004/04/21 19:40:51 kans
55
* ObjMgrReap calculate tempcnt based on temp loaded records, but excluded locked ones - more work still to do in other functions to completely avoid unnecessary thrashing
57
* Revision 6.51 2004/04/01 13:43:05 lavr
58
* Spell "occurred", "occurrence", and "occurring"
60
* Revision 6.50 2003/12/22 15:29:28 kans
61
* ObjMgrSendMsg calls SeqMgrClearFeatureIndexes on OM_MSG_DEL as well as OM_MSG_UPDATE
63
* Revision 6.49 2002/07/30 14:41:45 kans
64
* removed omdp->rearranged
66
* Revision 6.48 2002/07/29 21:30:17 kans
67
* added rearranged flag to omdp
69
* Revision 6.47 2002/07/01 14:29:02 kans
70
* changed totobj, currobj to Uint4
72
* Revision 6.46 2002/06/07 21:24:57 kans
73
* update entityID/omdp index in BioseqReloadFunc, ObjMgrConnectFunc, ObjMgrDetachFunc
75
* Revision 6.45 2002/06/01 05:52:00 vakatov
76
* Fix to R6.44 -- add LIBCALL and NLM_EXTERN modifiers to match the func proto
78
* Revision 6.44 2002/05/31 21:53:26 yaschenk
79
* changing lookup by EntityID to array[][]
43
81
* Revision 6.43 2001/12/13 13:59:14 kans
44
82
* ObjMgrSendMsg clears feature indexes if OM_MSG_UPDATE
521
#define ENTITY_ID_STACK_SIZE 100
523
static Uint2 recycledEntityIDs [ENTITY_ID_STACK_SIZE];
524
static Int4 recycledIDStackPt = 0;
563
static Uint4 assignedIDsArray [2050];
564
static Int2 assignedIDStackPt = 0;
565
static Boolean assignedIDsInited = FALSE;
567
static Uint4 assignedIDsBitIdx [32];
569
static Uint2 ObjMgrInitAssignedIDArray (void)
575
if (! assignedIDsInited) {
576
MemSet ((Pointer) &assignedIDsArray, 0, sizeof assignedIDsArray);
577
MemSet ((Pointer) &assignedIDsBitIdx, 0, sizeof (assignedIDsBitIdx));
579
/* initialize bit index array */
582
for (jdx = 0; jdx < 32; jdx++) {
583
assignedIDsBitIdx [jdx] = bit;
587
/* entityID 0 is not available for use */
589
assignedIDsArray [0] = assignedIDsBitIdx [0];
591
assignedIDStackPt = 0;
592
assignedIDsInited = TRUE;
596
static Uint2 ObjMgrNextAvailEntityID (ObjMgrPtr omp)
603
if (! assignedIDsInited) {
604
ObjMgrInitAssignedIDArray ();
607
/* find first 32 bit word with an available entityID */
609
idx = assignedIDStackPt;
610
while (idx < 2048 && assignedIDsArray [idx] == 0xFFFFFFFF) {
614
ErrPostEx (SEV_ERROR, 0, 0, "ObjMgrNextAvailEntityID failed with idx %d", (int) idx);
618
/* reset starting point, everything below should be in use */
620
assignedIDStackPt = idx;
622
/* find first empty bit in array element */
624
val = assignedIDsArray [idx];
626
while (jdx < 32 && (val & assignedIDsBitIdx [jdx]) != 0) {
630
ErrPostEx (SEV_ERROR, 0, 0, "ObjMgrNextAvailEntityID failed with jdx %d", (int) jdx);
634
/* set bit to mark new entityID as in use */
636
assignedIDsArray [idx] |= assignedIDsBitIdx [jdx];
638
/* calculate entityID */
640
entityID = (Uint2) ((Int4) idx) * 32L + (Int4) jdx;
642
if (omp != NULL && omp->HighestEntityID < entityID) {
643
omp->HighestEntityID = entityID;
649
static void ObjMgrRecycleEntityID (Uint2 entityID, ObjMgrPtr omp)
654
if (! assignedIDsInited) {
655
ObjMgrInitAssignedIDArray ();
658
if (entityID < 1) return;
660
idx = (Int2) (entityID / 32);
661
jdx = (Int2) (entityID % 32);
663
if (idx >= 2048 || idx < 0) {
664
ErrPostEx (SEV_ERROR, 0, 0, "ObjMgrRecycleEntityID failed with idx %d", (int) idx);
667
if (jdx >= 32 || jdx < 0) {
668
ErrPostEx (SEV_ERROR, 0, 0, "ObjMgrRecycleEntityID failed with jdx %d", (int) jdx);
672
/* clear bit to mark old entityID as available */
674
assignedIDsArray [idx] ^= assignedIDsBitIdx [jdx];
676
/* reset starting point, everything below should be in use */
678
if (idx < assignedIDStackPt) {
679
assignedIDStackPt = idx;
526
683
extern void ObjMgrRemoveEntityIDFromRecycle (Uint2 entityID, ObjMgrPtr omp);
527
684
extern void ObjMgrRemoveEntityIDFromRecycle (Uint2 entityID, ObjMgrPtr omp)
532
if (entityID < 1) return;
534
for (i = 0; i < recycledIDStackPt; i++) {
535
if (entityID == recycledEntityIDs [i]) {
536
recycledEntityIDs [i] = 0; /* remove from recycle list */
537
if (recycledIDStackPt > i + 1) {
539
recycledEntityIDs [i] = recycledEntityIDs [recycledIDStackPt];
548
static Uint2 ObjMgrNextAvailEntityID (ObjMgrPtr omp)
553
if (recycledIDStackPt > 0) {
555
entityID = recycledEntityIDs [recycledIDStackPt];
557
entityID = ++(omp->HighestEntityID);
563
static void ObjMgrRecycleEntityID (Uint2 entityID, ObjMgrPtr omp)
569
if (entityID < 1) return;
571
/* check to see if entity is already on stack (e.g., entity 1), abort if so */
572
for (i = 0; i < recycledIDStackPt; i++) {
573
if (entityID == recycledEntityIDs [i]) return;
575
if (recycledIDStackPt < ENTITY_ID_STACK_SIZE) {
576
recycledEntityIDs [recycledIDStackPt] = entityID;
689
if (! assignedIDsInited) {
690
ObjMgrInitAssignedIDArray ();
693
if (entityID < 1) return;
695
idx = (Int2) (entityID / 32);
696
jdx = (Int2) (entityID % 32);
698
if (idx >= 2048 || idx < 0) return;
699
if (jdx >= 32 || jdx < 0) return;
701
/* set bit to restore old entityID status to in use */
703
assignedIDsArray [idx] |= assignedIDsBitIdx [jdx];
582
706
NLM_EXTERN Uint2 LIBCALL ObjMgrAddEntityID (ObjMgrPtr omp, ObjMgrDataPtr omdp)
4790
4938
FileClose (fp);
4942
NLM_EXTERN void LIBCALL
4943
ObjMgrAddIndexOnEntityID(ObjMgrPtr omp,Uint2 entityID,ObjMgrDataPtr omdp)
4949
if(omp==NULL) omp=ObjMgrGet();
4951
if(!omp->entityID_index){
4952
omp->entityID_index=MemNew(256*sizeof(*omp->entityID_index));
4954
if(!omp->entityID_index[h]){
4955
omp->entityID_index[h]=MemNew(256*sizeof(**omp->entityID_index));
4957
omp->entityID_index[h][l]=omdp;
4962
NLM_EXTERN void LIBCALL
4963
ObjMgrDeleteIndexOnEntityID(ObjMgrPtr omp,Uint2 entityID)
4969
if(omp==NULL) omp=ObjMgrGet();
4970
if(omp && omp->entityID_index && omp->entityID_index[h]){
4971
omp->entityID_index[h][l]=NULL;
4977
NLM_EXTERN ObjMgrDataPtr LIBCALL
4978
ObjMgrLookupIndexOnEntityID(ObjMgrPtr omp,Uint2 entityID)
4984
if(omp==NULL) omp=ObjMgrGet();
4985
if(omp && omp->entityID_index && omp->entityID_index[h]){
4986
return omp->entityID_index[h][l];