GIFHASH.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version >= 1.0 - Modelling, Animation and Rendering Package
00003 -- */
00004 
00005 /* file GIFHASH.C   */
00006 
00007 #include "render.h"
00008 #undef OK
00009 #include "giflib.h"
00010 #include "gifhash.h"
00011 
00012 #ifdef _SUNSTYLE
00013 static long KeyItem();
00014 #else
00015 static long KeyItem(unsigned long Item);
00016 #endif
00017 
00018 /******************************************************************************
00019 * Initialize HashTable - allocate the memory needed and clear it.             *
00020 ******************************************************************************/
00021 #ifdef _SUNSTYLE
00022 GifHashTableType *_InitHashTable(){
00023 #else
00024 GifHashTableType *_InitHashTable(void){
00025 #endif
00026     GifHashTableType  *HashTable;
00027     if ((HashTable = (GifHashTableType *) X__Malloc(sizeof(GifHashTableType)))
00028                   == NULL) return NULL;
00029     _ClearHashTable(HashTable);
00030     return HashTable;
00031 }
00032 
00033 /******************************************************************************
00034 * Routine to clear the HashTable to an empty state.                           *
00035 * This part is a little machine depended. Use the commented part otherwise.   *
00036 ******************************************************************************/
00037 #ifdef _SUNSTYLE
00038 void _ClearHashTable(HashTable) GifHashTableType *HashTable; {
00039 #else
00040 void _ClearHashTable(GifHashTableType *HashTable){
00041 #endif    
00042     memset(HashTable -> HTable, 0xFF, HT_SIZE * sizeof(long));
00043 }
00044 
00045 /******************************************************************************
00046 * Routine to insert a new Item into the HashTable. The data is assumed to be  *
00047 * new one.                                                                    *
00048 ******************************************************************************/
00049 #ifdef _SUNSTYLE
00050 void _InsertHashTable(HashTable,Key,Code) GifHashTableType *HashTable;
00051 unsigned long Key; long Code; {
00052 #else
00053 void _InsertHashTable(GifHashTableType *HashTable,
00054         unsigned long Key, long Code){
00055 #endif
00056     long HKey = KeyItem(Key);
00057     unsigned long *HTable = HashTable -> HTable;
00058 
00059 
00060     while (HT_GET_KEY(HTable[HKey]) != 0xFFFFFL) {
00061       HKey = (HKey + 1) & HT_KEY_MASK;
00062     }
00063     HTable[HKey] = HT_PUT_KEY(Key) | HT_PUT_CODE(Code);
00064 }
00065 
00066 /******************************************************************************
00067 * Routine to test if given Key exists in HashTable and if so returns its code *
00068 * Returns the Code if key was found, -1 if not.                               *
00069 ******************************************************************************/
00070 #ifdef _SUNSTYLE
00071 long _ExistsHashTable(HashTable,Key) GifHashTableType *HashTable;
00072 unsigned long Key; {
00073 #else
00074 long _ExistsHashTable(GifHashTableType *HashTable, unsigned long Key){
00075 #endif
00076     long HKey = KeyItem(Key);
00077     unsigned long *HTable = HashTable -> HTable, HTKey;
00078 
00079 
00080     while ((HTKey = HT_GET_KEY(HTable[HKey])) != 0xFFFFFL) {
00081 if (Key == HTKey) return (long)(HT_GET_CODE(HTable[HKey]));
00082 HKey = (HKey + 1) & HT_KEY_MASK;
00083     }
00084 
00085     return -1;
00086 }
00087 
00088 /******************************************************************************
00089 * Routine to generate an HKey for the hashtable out of the given unique key.  *
00090 * The given Key is assumed to be 20 bits as follows: lower 8 bits are the     *
00091 * new postfix character, while the upper 12 bits are the prefix code.         *
00092 * Because the average hit ratio is only 2 (2 hash references per entry),      *
00093 * evaluating more complex keys (such as twin prime keys) does not worth it!   *
00094 ******************************************************************************/
00095 #ifdef _SUNSTYLE
00096 static long KeyItem(Item) unsigned long Item; {
00097 #else
00098 static long KeyItem(unsigned long Item){
00099 #endif
00100   return (long)(((Item >> 12) ^ Item) & HT_KEY_MASK);
00101 }
00102 

Generated on Sun Apr 27 14:20:13 2014 for OpenFX by  doxygen 1.5.6