hashfunc.c

来自「数据结构与算法分析(C语言描述)的源代码 里面的代码的质量非常高」· C语言 代码 · 共 40 行

C
40
字号
/* Here are some of the hash functions *//* for strings that are in the text */typedef unsigned int Index;/* START: fig5_3.txt */        Index        Hash1( const char *Key, int TableSize )        {            unsigned int HashVal = 0;/* 1*/      while( *Key != '\0' )/* 2*/          HashVal += *Key++;/* 3*/      return HashVal % TableSize;        }/* END *//* START: fig5_4.txt */        Index        Hash2( const char *Key, int TableSize )        {            return ( Key[ 0 ] + 27 * Key[ 1 ] + 729 * Key[ 2 ] )                        % TableSize;        }/* END *//* START: fig5_5.txt */        Index        Hash3( const char *Key, int TableSize )        {            unsigned int HashVal = 0;/* 1*/      while( *Key != '\0' )/* 2*/          HashVal = ( HashVal << 5 ) + *Key++;/* 3*/      return HashVal % TableSize;        }/* END */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?