00001 /*! \file hashfunc.c 00002 This file contains various hash functions. 00003 */ 00004 00005 #include "hashfunc.h" 00006 00007 00008 /*! \brief Calculate an index from a string of charecters. 00009 \param Key Pointer to a zero terminated string of characters. 00010 \param TableSize 'TableSize-1' represents the maximum value possible for the index. In other words, the value of 00011 the returned index will be such as: 0 <= index <= (TableSize-1). 00012 */ 00013 00014 Index Hash1( const char *Key, int TableSize ) 00015 { 00016 unsigned int HashVal = 0; 00017 00018 while(*Key != '\0') { HashVal += *Key++; } 00019 HashVal += *Key++; 00020 00021 return HashVal % TableSize; 00022 } 00023 00024 /*! \example test_hash_func.c 00025 This file shows how to use the hashing functions. 00026 */ 00027 00028 /*! \brief Calculate an index from a string of charecters. 00029 \param Key Pointer to a zero terminated string of characters. 00030 \param TableSize 'TableSize-1' represents the maximum value possible for the index. In other words, the value of 00031 the returned index will be such as: 0 <= index <= (TableSize-1). 00032 */ 00033 00034 Index Hash2( const char *Key, int TableSize ) 00035 { return ( Key[ 0 ] + 27 * Key[ 1 ] + 729 * Key[ 2 ] ) % TableSize; } 00036 00037 /*! \example test_hash_func.c 00038 This file shows how to use the hashing functions. 00039 */ 00040 00041 /*! \brief Calculate an index from a string of charecters. 00042 \param Key Pointer to a zero terminated string of characters. 00043 \param TableSize 'TableSize-1' represents the maximum value possible for the index. In other words, the value of 00044 the returned index will be such as: 0 <= index <= (TableSize-1). 00045 */ 00046 00047 Index Hash3( const char *Key, int TableSize ) 00048 { 00049 unsigned int HashVal = 0; 00050 00051 while( *Key != '\0' ) { HashVal = ( HashVal << 5 ) + *Key++; } 00052 00053 return HashVal % TableSize; 00054 } 00055 00056 /*! \example test_hash_func.c 00057 This file shows how to use the hashing functions. 00058 */ 00059