- 浏览: 247555 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
mabusyao:
漠北空城 写道请问下,你这个是JDK版本是多少呢?!忘记了,应 ...
HashMap 源码解读 -
漠北空城:
请问下,你这个是JDK版本是多少呢?!
HashMap 源码解读 -
schumee:
完美团队~
项目沉思录 - 1.1 -
winie:
整理下 搞成引擎嘛 国产需要这样的engine
简单工作流引擎 -
mabusyao:
某位同学给我提供的堪称完美的解决方案:1. 将三个int数组放 ...
CraneWork
感谢因特网提供的便利,暂时先放着,以后慢慢理解
转载 http://www.partow.net/programming/hashfunctions/
转载 http://www.partow.net/programming/hashfunctions/
/* ************************************************************************** * * * General Purpose Hash Function Algorithms Library * * * * Author: Arash Partow - 2002 * * URL: http://www.partow.net * * URL: http://www.partow.net/programming/hashfunctions/index.html * * * * Copyright notice: * * Free use of the General Purpose Hash Function Algorithms Library is * * permitted under the guidelines and in accordance with the most current * * version of the Common Public License. * * http://www.opensource.org/licenses/cpl1.0.php * * * ************************************************************************** */ class GeneralHashFunctionLibrary { public long RSHash(String str) { int b = 378551; int a = 63689; long hash = 0; for(int i = 0; i < str.length(); i++) { hash = hash * a + str.charAt(i); a = a * b; } return hash; } /* End Of RS Hash Function */ public long JSHash(String str) { long hash = 1315423911; for(int i = 0; i < str.length(); i++) { hash ^= ((hash << 5) + str.charAt(i) + (hash >> 2)); } return hash; } /* End Of JS Hash Function */ public long PJWHash(String str) { long BitsInUnsignedInt = (long)(4 * 8); long ThreeQuarters = (long)((BitsInUnsignedInt * 3) / 4); long OneEighth = (long)(BitsInUnsignedInt / 8); long HighBits = (long)(0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth); long hash = 0; long test = 0; for(int i = 0; i < str.length(); i++) { hash = (hash << OneEighth) + str.charAt(i); if((test = hash & HighBits) != 0) { hash = (( hash ^ (test >> ThreeQuarters)) & (~HighBits)); } } return hash; } /* End Of P. J. Weinberger Hash Function */ public long ELFHash(String str) { long hash = 0; long x = 0; for(int i = 0; i < str.length(); i++) { hash = (hash << 4) + str.charAt(i); if((x = hash & 0xF0000000L) != 0) { hash ^= (x >> 24); } hash &= ~x; } return hash; } /* End Of ELF Hash Function */ public long BKDRHash(String str) { long seed = 131; // 31 131 1313 13131 131313 etc.. long hash = 0; for(int i = 0; i < str.length(); i++) { hash = (hash * seed) + str.charAt(i); } return hash; } /* End Of BKDR Hash Function */ public long SDBMHash(String str) { long hash = 0; for(int i = 0; i < str.length(); i++) { hash = str.charAt(i) + (hash << 6) + (hash << 16) - hash; } return hash; } /* End Of SDBM Hash Function */ public long DJBHash(String str) { long hash = 5381; for(int i = 0; i < str.length(); i++) { hash = ((hash << 5) + hash) + str.charAt(i); } return hash; } /* End Of DJB Hash Function */ public long DEKHash(String str) { long hash = str.length(); for(int i = 0; i < str.length(); i++) { hash = ((hash << 5) ^ (hash >> 27)) ^ str.charAt(i); } return hash; } /* End Of DEK Hash Function */ public long BPHash(String str) { long hash = 0; for(int i = 0; i < str.length(); i++) { hash = hash << 7 ^ str.charAt(i); } return hash; } /* End Of BP Hash Function */ public long FNVHash(String str) { long fnv_prime = 0x811C9DC5; long hash = 0; for(int i = 0; i < str.length(); i++) { hash *= fnv_prime; hash ^= str.charAt(i); } return hash; } /* End Of FNV Hash Function */ public long APHash(String str) { long hash = 0xAAAAAAAA; for(int i = 0; i < str.length(); i++) { if ((i & 1) == 0) { hash ^= ((hash << 7) ^ str.charAt(i) * (hash >> 3)); } else { hash ^= (~((hash << 11) + str.charAt(i) ^ (hash >> 5))); } } return hash; } /* End Of AP Hash Function */ }
发表评论
-
大数据下的实体解析
2016-07-07 12:03 671大数据时代的实体解析困境 <!--[if !sup ... -
中文相似度匹配算法
2015-12-30 14:44 1921基于音形码的中文字 ... -
各种语言写的wordcount
2015-09-24 16:07 0Java版本: String input ... -
数组双指针算法的研究
2015-07-14 16:59 2418双指针算法在数组/链 ... -
摩尔投票法
2015-06-30 20:13 18276摩尔投票法 提问: 给定一个int型数组,找出该数 ... -
(转)最长回文字串算法
2015-01-18 14:30 1397来自(http://blog.163.com/zhaohai ... -
STRUTS2 源码 - Logging System
2012-05-24 08:51 1357看了STRUTS2的源码,了解了它的logging系统,觉得还 ... -
在线词典的数据结构实现。
2012-05-18 08:37 0昨天在网上看到了一道百度的面试题: Baidu写道 ... -
存储中间计算结果的动态规划算法
2012-04-18 15:50 1179public class RodCutting { ... -
java写的四则运算器
2011-08-19 22:19 2660本打算做一个从RE到NFA的转换器,思路已经理清了,但是在动手 ... -
什么是最小二乘拟合
2007-09-14 21:27 924对于一个数据点(x1, y1), ... (xn, yn)的集 ... -
palindrome
2008-07-14 17:39 951package palindrome;/*Problem St ... -
CraneWork
2008-07-14 19:14 953/*Problem Statement There are ... -
SalesRouting
2008-07-15 10:53 740package salesRouting;/*Problem ... -
FactorialSystem
2008-07-21 19:36 818/*Problem StatementIn the facto ... -
RecurringNumbers
2008-07-22 09:41 884/*Problem StatementA rational n ... -
HardDuplicateRemover
2008-07-23 15:17 878/*Problem StatementWe have a se ... -
BlockStructure
2008-07-23 20:55 761/*Problem StatementA group of v ... -
SkipStones
2008-07-28 17:31 791/*Problem StatementWhen a stone ... -
TheaterVisit
2008-07-28 17:31 742/*Problem StatementYou want to ...
相关推荐
常见的HASH算法
采用java实现的常用hash算法归总。
Hash函数集合,包含主流的hash函数: nginx_hash算法,OpenSSL_hash算法,RSHash,JSHash,PJWHash,ELFHash,BKDRHash,DJBHash,DEKHash,APHash等等!
IT面试常见的题目,对于分布式存储系统中常碰到的故障问题,如何解决,就是采用一致性hash算法
Objective-C 中 NSString 关于常见 Hash 算法的分类,能对字符串,文件进行 Hash 运算,具备 HMAC 功能。支持的 Hash 算法有:MD5、SHA1、SHA256、SHA512。
2. 由于Hash逼近单向函数 3. 不同的应用对Hash函数有着不同的要求 2. 长数组的Hash
。。。
。。。
常见加密算法及身份验证协议探究 加密 对称加密 非对称加密 HASH 公共密钥体系 证书服务器的安装和配置及SSL的应用 身份验证 身份验证方法 智能卡身份验证 NTLM和Kerberos
H a s h 算法在信息安全领域中具有文件校验、 数字签名、 鉴权协议等主要应用, 其算法是将任意长度的...换成固定长度的愉出, 常见的算法有M D 4 , M D 5 , S H A - 1 等; H A S H算法在现代密码学中 有着广泛的应用。
常见算法及部分java实现。。。包括各种排序算法、红黑树、负载均衡算法、crc算法、摘要算法、对称非对称加密算法、一致性hash算法等等。。。
数据结构,西安电子科技大学出版社那本书里的所有程序 包HASH算法,数组排序等一些常见算法
此题,在我之前的一篇文章算法里头有所提到,当时给出的方案是:IP的数目还是有限的,最多2^32个,所以可以考虑使用hash将ip直接存入内存,然后进行统计。 再详细介绍下此方案:首先是这一天,并且是访问百度的日志...
关于hash-encrypt 本项目只是把几个常见的c++ hash算法转成js。这几个hash算法是: RSHash JSHash ELFHash BKDRHash SDBMHash DJBHash APHash 可以拿对应的js即可
约瑟夫环问题,魔方算法 迷宫探路 有向图强连通分量 线段树解在程序中的应用 Tarjan算法 Hash函数英语 RMQ算法
吉林大学硕士论文完整原版,MD5算法研究,算法原理,常见优秀hash函数,MD5算法优化等。
这篇文章主要介绍了Python hashlib常见摘要算法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等 ...
STM32加密算法库,包含常见的加密算法,AES、ARC4、ECC、HASH、RAND、RSA、TDES_DES等加密算法
常见的数据结构有数组、链表、栈、队列、树、图等。 算法则是解决特定问题的步骤,是对数据运算和操作的详细描述。算法的设计和选择会直接影响到程序的效率,因此,在设计和选择算法时,需要考虑到时间复杂度、空间...
字符串匹配算法(模式搜索 Pattern ...常见的字符串匹配算法: 1、BF(Brute Force,暴力算法); 2、RK (Robin-Karp 算法); 3、KMP (D.E.Knuth、J.H.Morris、V.R.Pratt 算法); 4、哈希Hash与移动哈希算法;