若干经典哈希算法
来源:互联网 发布:立方米网络 编辑:程序博客网 时间:2024/06/05 15:19
- // RS Hash Function
- unsigned int RSHash( char * str)
- {
- unsigned int b = 378551 ;
- unsigned int a = 63689 ;
- unsigned int hash = 0 ;
- while ( * str)
- {
- hash = hash * a + ( * str ++ );
- a *= b;
- }
- return (hash & 0x7FFFFFFF );
- }
- // JS Hash Function
- unsigned int JSHash( char * str)
- {
- unsigned int hash = 1315423911 ;
- while ( * str)
- {
- hash ^= ((hash << 5 ) + ( * str ++ ) + (hash >> 2 ));
- }
- return (hash & 0x7FFFFFFF );
- }
- // P. J. Weinberger Hash Function
- unsigned int PJWHash( char * str)
- {
- unsigned int BitsInUnignedInt = (unsigned int )( sizeof (unsigned int ) *
- 8 );
- unsigned int ThreeQuarters = (unsigned int )((BitsInUnignedInt * 3 )
- / 4 );
- unsigned int OneEighth = (unsigned int )(BitsInUnignedInt / 8 );
- unsigned int HighBits = (unsigned int )( 0xFFFFFFFF ) << (BitsInU
- nignedInt - OneEighth);
- unsigned int hash = 0 ;
- unsigned int test = 0 ;
- while ( * str)
- {
- hash = (hash << OneEighth) + ( * str ++ );
- if ((test = hash & HighBits) != 0 )
- {
- hash = ((hash ^ (test >> ThreeQuarters)) & ( ~ HighBits)
- );
- }
- }
- return (hash & 0x7FFFFFFF );
- }
- // ELF Hash Function
- unsigned int ELFHash( char * str)
- {
- unsigned int hash = 0 ;
- unsigned int x = 0 ;
- while ( * str)
- {
- hash = (hash << 4 ) + ( * str ++ );
- if ((x = hash & 0xF0000000L ) != 0 )
- {
- hash ^= (x >> 24 );
- hash &= ~ x;
- }
- }
- return (hash & 0x7FFFFFFF );
- }
- // BKDR Hash Function
- unsigned int BKDRHash( char * str)
- {
- unsigned int seed = 131 ; // 31 131 1313 13131 131313 etc..
- unsigned int hash = 0 ;
- while ( * str)
- {
- hash = hash * seed + ( * str ++ );
- }
- return (hash & 0x7FFFFFFF );
- }
- // SDBM Hash Function
- unsigned int SDBMHash( char * str)
- {
- unsigned int hash = 0 ;
- while ( * str)
- {
- hash = ( * str ++ ) + (hash << 6 ) + (hash << 16 ) - hash;
- }
- return (hash & 0x7FFFFFFF );
- }
- // DJB Hash Function
- unsigned int DJBHash( char * str)
- {
- unsigned int hash = 5381 ;
- while ( * str)
- {
- hash += (hash << 5 ) + ( * str ++ );
- }
- return (hash & 0x7FFFFFFF );
- }
- // AP Hash Function
- unsigned int APHash( char * str)
- {
- unsigned int hash = 0 ;
- int i;
- for (i = 0 ; * str; i ++ )
- {
- if ((i & 1 ) == 0 )
- {
- hash ^= ((hash << 7 ) ^ ( * str ++ ) ^ (hash >> 3 ));
- }
- else
- {
- hash ^= ( ~ ((hash << 11 ) ^ ( * str ++ ) ^ (hash >> 5 )));
- }
- }
- return (hash & 0x7FFFFFFF );
- }
- 若干经典哈希算法
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 若干经典的字符串哈希函数
- 数据结构若干经典问题和算法 (收藏)
- 若干经典基础算法题目练习
- 若干经典的字符串哈希函数(转)
- 若干经典面试题
- 【经典算法】:哈希方法
- 若干算法题目备忘
- activerecord安全传递参数的方法
- J2ME 下的 Base64的编码与解码
- DIV+CSS神话
- 软件架构的完美原则
- 3G来了,我们能干点啥软件?
- 若干经典哈希算法
- SmartTemplate更名为QuickSkin (formerly SmartTemplate)
- JavaScript中的delete操作符
- 手动找回误删文件
- Debugging a SQL Stored Procedure from inside SQL Server 2000 Query Analyzer
- 正则表达式
- JAVA基础学习篇----Eclipse进行(JBOSS)远程调试
- Microsoft testing a better rival to Google Docs
- Eclipse3.3以上多国语言包下载