home *** CD-ROM | disk | FTP | other *** search
-
- /* File: /u1/Eden/Kernel/MsgOps/KeyedCode.c */
-
- /*
- * $Header: /u1/Eden/Kernel/MsgOps/RCS/KeyedCode.v Revision 1.6 85/03/14 11:43:06 eric Exp$
- * INTERFACE: Defined by exported procedures.
- *
- * FUNCTION: Message Module Keyed Queue Services.
- *
- * IMPORTS: Eden/Source/MsgOps/Types.h,
- * /u1/Eden/ErrCodes/MMcodes.h,
- * /u1/Eden/Source/MsgOps/BufferTypes.h,
- * /u1/Eden/Source/MsgOps/FifoTypes.h.
- *
- * EXPORTS: MMInitList, MMEnterInList, MMGetFromList,
- * MMFindInList.
- *
- * DESIGN: Keyed queues are structured as hashed lists based
- * on a key supplied by the user of the queue. The
- * has algorithm simply consists of taking the key
- * modulo the hash table size as an index into the
- * queue hash table. Collisions are resolved by
- * constructing a linked list of entries in decreasing
- * order. Duplicate key entries are not currently
- * allowed.
- *
- * $Log: /u1/Eden/Source/MsgOps/RCS/KeyedCode.v $
- * Revision 1.6 85/03/14 11:43:06 eric
- * Minor changes to MXTraceMsg.
- *
- * Revision 1.5 83/03/19 11:43:06 cady
- * Modified to allow NULL data and key pointer parameters.
- *
- * Revision 1.4 83/02/25 12:16:06 cady
- * Added new trace levels.
- *
- * Revision 1.3 83/02/24 16:40:37 cady
- * Replaced conditional debug trace with dynamic trace.
- * Added conditional Kernel compilation.
- *
- * Revision 1.2 83/02/22 12:06:23 cady
- * Replaced #if Debug with #ifdef Debug.
- *
- * Revision 1.1 83/01/06 14:09:20 cady
- * Initial revision
- *
- * 4-Nov-1982 Initial implementation. S. Cady
- */
-
- /****************************************************************/
- /* */
- /* Message Module Keyed Queue Library */
- /* */
- /****************************************************************/
-
- #include "Kernel/h/mmTypes.h"
- #include "Kernel/h/mmCodes.h"
- #include "Kernel/h/mmBufTypes.h"
- #include "Kernel/h/mmKeyTypes.h"
-
- /* Keyed Queue Hash Function */
-
- #define mHashKey(fKey) (((int)(fKey)) % KEYEDSIZE)
-
- /****************************************************************/
- /* */
- /* MMInitList */
- /* */
- /* MMInitList defines the specified keyed queue to be empty. */
- /* */
- /****************************************************************/
-
- void MMInitList( fList /* Keyed Queue */
- )
- KeyedQueue fList;
- {
- register int i;
-
- MXTraceMsg(4, "MMInitList( %d )\n", fList);
-
- for ( i = 0; i < KEYEDSIZE; i++ )
- fList[i] = NULL;
- }
-
- /****************************************************************/
- /* */
- /* FindEntry */
- /* */
- /****************************************************************/
-
- static KKStatus FindEntry( fList, /* Keyed Queue */
- fKey, /* Search Key */
- /* returns */ fPrev, /* Preceding Entry */
- /* returns */ fEntry /* Found Entry */
- )
- KeyedQueue fList;
- register UnsignedInteger fKey;
- KeyedEltPtr *fPrev, *fEntry;
- {
- register KeyedEltPtr prev;
- register KeyedEltPtr next;
-
- prev = NULL;
- next = fList[mHashKey(fKey)];
- while ( next != NULL )
- if ( next->KeyedKey < fKey )
- break;
- else if ( next->KeyedKey == fKey )
- { *fPrev = prev;
- *fEntry = next;
- return MMSS_Success;
- }
- else { prev = next;
- next = next->KeyedNext;
- };
- /* end while */
- *fPrev = prev;
- *fEntry = next;
- return MMSF_NoEntry;
- }
-
- /****************************************************************/
- /* */
- /* MMEnterInList */
- /* */
- /* MMEnterInList creates an entry containing the specified key */
- /* and data and inserts it into the keyed list. */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSK_NoMem, MMSF_Dupl */
- /* */
- /****************************************************************/
-
- KKStatus MMEnterInList( fList, /* Keyed Queue */
- fKey, /* Search key */
- fData1, /* Entry data */
- fData2
- )
- KeyedQueue fList;
- UnsignedInteger fKey;
- integer fData1, fData2;
- {
- int index;
- KeyedEltPtr old;
- KeyedEltPtr new;
-
-
- MXTraceMsg(5, "MMEnterInList( %d, %d, %d, %d )\n", fList,
- fKey, fData1, fData2);
-
- if ( mSUCCESS(FindEntry( fList, fKey, &old, &new )) )
- return MMSF_Dupl;
- if ( ! mSUCCESS(MMAllocateData(sizeof(KeyedElt), (char **) &new)) )
- return MMSK_NoMem;
- new->KeyedKey = fKey;
- new->KeyedData[0] = fData1;
- new->KeyedData[1] = fData2;
- if ( old == NULL )
- { index = mHashKey(fKey);
- new->KeyedNext = fList[index];
- fList[index] = new;
- }
- else
- { new->KeyedNext = old->KeyedNext;
- old->KeyedNext = new;
- };
- return MMSS_Success;
- }
-
- /****************************************************************/
- /* */
- /* MMGetFromList */
- /* */
- /* MMGetFromList searches the queue for an entry with the */
- /* specified key. If the key is found, the entry is removed */
- /* from the queue and the data is returned. If the key is not */
- /* found, an error status is returned. */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSF_NoEntry */
- /* */
- /****************************************************************/
-
- KKStatus MMGetFromList( fList, /* Keyed Queue */
- fKey, /* Search key */
- fData1, /* Entry Data */
- fData2
- )
- KeyedQueue fList;
- UnsignedInteger fKey;
- integer *fData1, *fData2;
- {
- KeyedEltPtr prev, entry;
-
-
- MXTraceMsg(5, "MMGetFromList( %d, %d )\n", fList, fKey);
-
- if ( ! mSUCCESS(FindEntry( fList, fKey, &prev, &entry )) )
- return MMSF_NoEntry;
- if ( prev == NULL )
- fList[mHashKey(fKey)] = entry->KeyedNext;
- else
- prev->KeyedNext = entry->KeyedNext;
- if ( fData1 != NULL )
- *fData1 = entry->KeyedData[0];
- if ( fData2 != NULL )
- *fData2 = entry->KeyedData[1];
- MMDeallocateData( sizeof(KeyedElt), (char *) entry );
-
- return MMSS_Success;
- }
-
- /****************************************************************/
- /* */
- /* MMFindInList */
- /* */
- /* MMFindInList searches the queue for an entry with the */
- /* specified key. If the key is found, the entry data is */
- /* returned, but the entry is not removed from the queue. */
- /* If the key is not found, an error status is returned. */
- /* */
- /* Possible status codes: */
- /* MMSS_Success, MMSF_NoEntry */
- /* */
- /****************************************************************/
-
- KKStatus MMFindInList( fList, /* Keyed Queue */
- fKey, /* Search Key */
- fData1, /* Entry Data */
- fData2
- )
- KeyedQueue fList;
- UnsignedInteger fKey;
- integer *fData1, *fData2;
- {
- KeyedEltPtr prev, entry;
-
-
- MXTraceMsg(5, "MMFindInList( %d, %d )\n", fList, fKey);
-
- if ( ! mSUCCESS(FindEntry( fList, fKey, &prev, &entry )) )
- return MMSF_NoEntry;
- if ( fData1 != NULL )
- *fData1 = entry->KeyedData[0];
- if ( fData2 != NULL )
- *fData2 = entry->KeyedData[1];
-
-
- MXTraceMsg(6, "Found: %d, %d\n", *fData1, *fData2);
-
- return MMSS_Success;
- }
- /****************************************************************/
- /* End of Message Module Keyed Queue Library */
- /****************************************************************/
-