- 浏览: 54108 次
- 性别:
- 来自: 北京
最新评论
-
羽翼的心动:
POI代码是在服务器端执行的,直接操作处理的是服务器端的文件, ...
大数据量导出Excel的方案 POI、JXL、FastExcel比较 -
zwt2001267:
It works
Property path [...] does not reference a collection -
nikoused:
请问解决了吗?我也碰到而且我的cellstyle都没了
poi操作Excel2007后打开老弹出提示框 -
nb125:
大神,用些xml 的方式 能不能找到sheet页 在后追加
大数据量导出Excel的方案 POI、JXL、FastExcel比较 -
ih0qtq:
<以上方法虽然实现了向excel中插入图片,但是下载下来 ...
POI实现Excel插入图片
package com.conan;
/**
* Hash算法大全<br>
* 推荐使用FNV1算法
*
* @algorithm None
* @author Goodzzp 2006-11-20
* @lastEdit Goodzzp 2006-11-20
* @editDetail Create
*/
public class HashAlgorithms {
/**
* 加法hash
*
* @param key
* 字符串
* @param prime
* 一个质数
* @return hash结果
*/
public static int additiveHash(String key, int prime) {
int hash, i;
for (hash = key.length(), i = 0; i < key.length(); i++)
hash += key.charAt(i);
return (hash % prime);
}
/**
* 旋转hash
*
* @param key
* 输入字符串
* @param prime
* 质数
* @return hash值
*/
public static int rotatingHash(String key, int prime) {
int hash, i;
for (hash = key.length(), i = 0; i < key.length(); ++i)
hash = (hash << 4) ^ (hash >> 28) ^ key.charAt(i);
return (hash % prime);
// return (hash ^ (hash>>10) ^ (hash>>20));
}
// 替代:
// 使用:hash = (hash ^ (hash>>10) ^ (hash>>20)) & mask;
// 替代:hash %= prime;
/**
* MASK值,随便找一个值,最好是质数
*/
static int M_MASK = 0x8765fed1;
/**
* 一次一个hash
*
* @param key
* 输入字符串
* @return 输出hash值
*/
public static int oneByOneHash(String key) {
int hash, i;
for (hash = 0, i = 0; i < key.length(); ++i) {
hash += key.charAt(i);
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
// return (hash & M_MASK);
return hash;
}
/**
* Bernstein's hash
*
* @param key
* 输入字节数组
* @param level
* 初始hash常量
* @return 结果hash
*/
public static int bernstein(String key) {
int hash = 0;
int i;
for (i = 0; i < key.length(); ++i)
hash = 33 * hash + key.charAt(i);
return hash;
}
//
// // Pearson's Hash
// char pearson(char[]key, ub4 len, char tab[256])
// {
// char hash;
// ub4 i;
// for (hash=len, i=0; i<len; ++i)
// hash=tab[hash^key[i]];
// return (hash);
// }
// // CRC Hashing,计算crc,具体代码见其他
// ub4 crc(char *key, ub4 len, ub4 mask, ub4 tab[256])
// {
// ub4 hash, i;
// for (hash=len, i=0; i<len; ++i)
// hash = (hash >> ^ tab[(hash & 0xff) ^ key[i]];
// return (hash & mask);
// }
/**
* Universal Hashing
*/
public static int universal(char[] key, int mask, int[] tab) {
int hash = key.length, i, len = key.length;
for (i = 0; i < (len << 3); i += {
char k = key[i >> 3];
if ((k & 0x01) == 0)
hash ^= tab[i + 0];
if ((k & 0x02) == 0)
hash ^= tab[i + 1];
if ((k & 0x04) == 0)
hash ^= tab[i + 2];
if ((k & 0x08) == 0)
hash ^= tab[i + 3];
if ((k & 0x10) == 0)
hash ^= tab[i + 4];
if ((k & 0x20) == 0)
hash ^= tab[i + 5];
if ((k & 0x40) == 0)
hash ^= tab[i + 6];
if ((k & 0x80) == 0)
hash ^= tab[i + 7];
}
return (hash & mask);
}
/**
* Zobrist Hashing
*/
public static int zobrist(char[] key, int mask, int[][] tab) {
int hash, i;
for (hash = key.length, i = 0; i < key.length; ++i)
hash ^= tab[i][key[i]];
return (hash & mask);
}
// LOOKUP3
// 见Bob Jenkins(3).c文件
// 32位FNV算法
static int M_SHIFT = 0;
/**
* 32位的FNV算法
*
* @param data
* 数组
* @return int值
*/
public static int FNVHash(byte[] data) {
int hash = (int) 2166136261L;
for (byte b : data)
hash = (hash * 16777619) ^ b;
if (M_SHIFT == 0)
return hash;
return (hash ^ (hash >> M_SHIFT)) & M_MASK;
}
/**
* 改进的32位FNV算法1
*
* @param data
* 数组
* @return int值
*/
public static int FNVHash1(byte[] data) {
final int p = 16777619;
int hash = (int) 2166136261L;
for (byte b : data)
hash = (hash ^ b) * p;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
/**
* 改进的32位FNV算法1
*
* @param data
* 字符串
* @return int值
*/
public static int FNVHash1(String data) {
final int p = 16777619;
int hash = (int) 2166136261L;
for (int i = 0; i < data.length(); i++)
hash = (hash ^ data.charAt(i)) * p;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
/**
* Thomas Wang的算法,整数hash
*/
public static int intHash(int key) {
key += ~(key << 15);
key ^= (key >>> 10);
key += (key << 3);
key ^= (key >>> 6);
key += ~(key << 11);
key ^= (key >>> 16);
return key;
}
/**
* RS算法hash
*
* @param str
* 字符串
*/
public static int RSHash(String str) {
int b = 378551;
int a = 63689;
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash = hash * a + str.charAt(i);
a = a * b;
}
return (hash & 0x7FFFFFFF);
}
/* End Of RS Hash Function */
/**
* JS算法
*/
public static int JSHash(String str) {
int hash = 1315423911;
for (int i = 0; i < str.length(); i++) {
hash ^= ((hash << 5) + str.charAt(i) + (hash >> 2));
}
return (hash & 0x7FFFFFFF);
}
/* End Of JS Hash Function */
/**
* PJW算法
*/
public static int PJWHash(String str) {
int BitsInUnsignedInt = 32;
int ThreeQuarters = (BitsInUnsignedInt * 3) / 4;
int OneEighth = BitsInUnsignedInt / 8;
int HighBits = 0xFFFFFFFF << (BitsInUnsignedInt - OneEighth);
int hash = 0;
int 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 & 0x7FFFFFFF);
}
/* End Of P. J. Weinberger Hash Function */
/**
* ELF算法
*/
public static int ELFHash(String str) {
int hash = 0;
int x = 0;
for (int i = 0; i < str.length(); i++) {
hash = (hash << 4) + str.charAt(i);
if ((x = (int) (hash & 0xF0000000L)) != 0) {
hash ^= (x >> 24);
hash &= ~x;
}
}
return (hash & 0x7FFFFFFF);
}
/* End Of ELF Hash Function */
/**
* BKDR算法
*/
public static int BKDRHash(String str) {
int seed = 131; // 31 131 1313 13131 131313 etc..
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash = (hash * seed) + str.charAt(i);
}
return (hash & 0x7FFFFFFF);
}
/* End Of BKDR Hash Function */
/**
* SDBM算法
*/
public static int SDBMHash(String str) {
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash = str.charAt(i) + (hash << 6) + (hash << 16) - hash;
}
return (hash & 0x7FFFFFFF);
}
/* End Of SDBM Hash Function */
/**
* DJB算法
*/
public static int DJBHash(String str) {
int hash = 5381;
for (int i = 0; i < str.length(); i++) {
hash = ((hash << 5) + hash) + str.charAt(i);
}
return (hash & 0x7FFFFFFF);
}
/* End Of DJB Hash Function */
/**
* DEK算法
*/
public static int DEKHash(String str) {
int hash = str.length();
for (int i = 0; i < str.length(); i++) {
hash = ((hash << 5) ^ (hash >> 27)) ^ str.charAt(i);
}
return (hash & 0x7FFFFFFF);
}
/* End Of DEK Hash Function */
/**
* AP算法
*/
public static int APHash(String str) {
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str.charAt(i) ^ (hash >> 3))
: (~((hash << 11) ^ str.charAt(i) ^ (hash >> 5)));
}
// return (hash & 0x7FFFFFFF);
return hash;
}
/* End Of AP Hash Function */
/**
* JAVA自己带的算法
*/
public static int java(String str) {
int h = 0;
int off = 0;
int len = str.length();
for (int i = 0; i < len; i++) {
h = 31 * h + str.charAt(off++);
}
return h;
}
/**
* 混合hash算法,输出64位的值
*/
public static long mixHash(String str) {
long hash = str.hashCode();
hash <<= 32;
hash |= FNVHash1(str);
return hash;
}
}
/**
* Hash算法大全<br>
* 推荐使用FNV1算法
*
* @algorithm None
* @author Goodzzp 2006-11-20
* @lastEdit Goodzzp 2006-11-20
* @editDetail Create
*/
public class HashAlgorithms {
/**
* 加法hash
*
* @param key
* 字符串
* @param prime
* 一个质数
* @return hash结果
*/
public static int additiveHash(String key, int prime) {
int hash, i;
for (hash = key.length(), i = 0; i < key.length(); i++)
hash += key.charAt(i);
return (hash % prime);
}
/**
* 旋转hash
*
* @param key
* 输入字符串
* @param prime
* 质数
* @return hash值
*/
public static int rotatingHash(String key, int prime) {
int hash, i;
for (hash = key.length(), i = 0; i < key.length(); ++i)
hash = (hash << 4) ^ (hash >> 28) ^ key.charAt(i);
return (hash % prime);
// return (hash ^ (hash>>10) ^ (hash>>20));
}
// 替代:
// 使用:hash = (hash ^ (hash>>10) ^ (hash>>20)) & mask;
// 替代:hash %= prime;
/**
* MASK值,随便找一个值,最好是质数
*/
static int M_MASK = 0x8765fed1;
/**
* 一次一个hash
*
* @param key
* 输入字符串
* @return 输出hash值
*/
public static int oneByOneHash(String key) {
int hash, i;
for (hash = 0, i = 0; i < key.length(); ++i) {
hash += key.charAt(i);
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
// return (hash & M_MASK);
return hash;
}
/**
* Bernstein's hash
*
* @param key
* 输入字节数组
* @param level
* 初始hash常量
* @return 结果hash
*/
public static int bernstein(String key) {
int hash = 0;
int i;
for (i = 0; i < key.length(); ++i)
hash = 33 * hash + key.charAt(i);
return hash;
}
//
// // Pearson's Hash
// char pearson(char[]key, ub4 len, char tab[256])
// {
// char hash;
// ub4 i;
// for (hash=len, i=0; i<len; ++i)
// hash=tab[hash^key[i]];
// return (hash);
// }
// // CRC Hashing,计算crc,具体代码见其他
// ub4 crc(char *key, ub4 len, ub4 mask, ub4 tab[256])
// {
// ub4 hash, i;
// for (hash=len, i=0; i<len; ++i)
// hash = (hash >> ^ tab[(hash & 0xff) ^ key[i]];
// return (hash & mask);
// }
/**
* Universal Hashing
*/
public static int universal(char[] key, int mask, int[] tab) {
int hash = key.length, i, len = key.length;
for (i = 0; i < (len << 3); i += {
char k = key[i >> 3];
if ((k & 0x01) == 0)
hash ^= tab[i + 0];
if ((k & 0x02) == 0)
hash ^= tab[i + 1];
if ((k & 0x04) == 0)
hash ^= tab[i + 2];
if ((k & 0x08) == 0)
hash ^= tab[i + 3];
if ((k & 0x10) == 0)
hash ^= tab[i + 4];
if ((k & 0x20) == 0)
hash ^= tab[i + 5];
if ((k & 0x40) == 0)
hash ^= tab[i + 6];
if ((k & 0x80) == 0)
hash ^= tab[i + 7];
}
return (hash & mask);
}
/**
* Zobrist Hashing
*/
public static int zobrist(char[] key, int mask, int[][] tab) {
int hash, i;
for (hash = key.length, i = 0; i < key.length; ++i)
hash ^= tab[i][key[i]];
return (hash & mask);
}
// LOOKUP3
// 见Bob Jenkins(3).c文件
// 32位FNV算法
static int M_SHIFT = 0;
/**
* 32位的FNV算法
*
* @param data
* 数组
* @return int值
*/
public static int FNVHash(byte[] data) {
int hash = (int) 2166136261L;
for (byte b : data)
hash = (hash * 16777619) ^ b;
if (M_SHIFT == 0)
return hash;
return (hash ^ (hash >> M_SHIFT)) & M_MASK;
}
/**
* 改进的32位FNV算法1
*
* @param data
* 数组
* @return int值
*/
public static int FNVHash1(byte[] data) {
final int p = 16777619;
int hash = (int) 2166136261L;
for (byte b : data)
hash = (hash ^ b) * p;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
/**
* 改进的32位FNV算法1
*
* @param data
* 字符串
* @return int值
*/
public static int FNVHash1(String data) {
final int p = 16777619;
int hash = (int) 2166136261L;
for (int i = 0; i < data.length(); i++)
hash = (hash ^ data.charAt(i)) * p;
hash += hash << 13;
hash ^= hash >> 7;
hash += hash << 3;
hash ^= hash >> 17;
hash += hash << 5;
return hash;
}
/**
* Thomas Wang的算法,整数hash
*/
public static int intHash(int key) {
key += ~(key << 15);
key ^= (key >>> 10);
key += (key << 3);
key ^= (key >>> 6);
key += ~(key << 11);
key ^= (key >>> 16);
return key;
}
/**
* RS算法hash
*
* @param str
* 字符串
*/
public static int RSHash(String str) {
int b = 378551;
int a = 63689;
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash = hash * a + str.charAt(i);
a = a * b;
}
return (hash & 0x7FFFFFFF);
}
/* End Of RS Hash Function */
/**
* JS算法
*/
public static int JSHash(String str) {
int hash = 1315423911;
for (int i = 0; i < str.length(); i++) {
hash ^= ((hash << 5) + str.charAt(i) + (hash >> 2));
}
return (hash & 0x7FFFFFFF);
}
/* End Of JS Hash Function */
/**
* PJW算法
*/
public static int PJWHash(String str) {
int BitsInUnsignedInt = 32;
int ThreeQuarters = (BitsInUnsignedInt * 3) / 4;
int OneEighth = BitsInUnsignedInt / 8;
int HighBits = 0xFFFFFFFF << (BitsInUnsignedInt - OneEighth);
int hash = 0;
int 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 & 0x7FFFFFFF);
}
/* End Of P. J. Weinberger Hash Function */
/**
* ELF算法
*/
public static int ELFHash(String str) {
int hash = 0;
int x = 0;
for (int i = 0; i < str.length(); i++) {
hash = (hash << 4) + str.charAt(i);
if ((x = (int) (hash & 0xF0000000L)) != 0) {
hash ^= (x >> 24);
hash &= ~x;
}
}
return (hash & 0x7FFFFFFF);
}
/* End Of ELF Hash Function */
/**
* BKDR算法
*/
public static int BKDRHash(String str) {
int seed = 131; // 31 131 1313 13131 131313 etc..
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash = (hash * seed) + str.charAt(i);
}
return (hash & 0x7FFFFFFF);
}
/* End Of BKDR Hash Function */
/**
* SDBM算法
*/
public static int SDBMHash(String str) {
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash = str.charAt(i) + (hash << 6) + (hash << 16) - hash;
}
return (hash & 0x7FFFFFFF);
}
/* End Of SDBM Hash Function */
/**
* DJB算法
*/
public static int DJBHash(String str) {
int hash = 5381;
for (int i = 0; i < str.length(); i++) {
hash = ((hash << 5) + hash) + str.charAt(i);
}
return (hash & 0x7FFFFFFF);
}
/* End Of DJB Hash Function */
/**
* DEK算法
*/
public static int DEKHash(String str) {
int hash = str.length();
for (int i = 0; i < str.length(); i++) {
hash = ((hash << 5) ^ (hash >> 27)) ^ str.charAt(i);
}
return (hash & 0x7FFFFFFF);
}
/* End Of DEK Hash Function */
/**
* AP算法
*/
public static int APHash(String str) {
int hash = 0;
for (int i = 0; i < str.length(); i++) {
hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str.charAt(i) ^ (hash >> 3))
: (~((hash << 11) ^ str.charAt(i) ^ (hash >> 5)));
}
// return (hash & 0x7FFFFFFF);
return hash;
}
/* End Of AP Hash Function */
/**
* JAVA自己带的算法
*/
public static int java(String str) {
int h = 0;
int off = 0;
int len = str.length();
for (int i = 0; i < len; i++) {
h = 31 * h + str.charAt(off++);
}
return h;
}
/**
* 混合hash算法,输出64位的值
*/
public static long mixHash(String str) {
long hash = str.hashCode();
hash <<= 32;
hash |= FNVHash1(str);
return hash;
}
}
发表评论
-
JProfiler7远程监控resin4
2012-07-04 17:47 1753环境:window8、ubuntu10 服务器上装jprofi ... -
Service Temporarily Unavailable: Apache和Resin组合时间歇性出现503错误的解决方法
2012-04-09 11:29 1528使用Apache和Resin进行组 ... -
Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
2012-03-31 16:14 801什么是动态定时任务:是由客户制定生成的,服务端只知道该去执行什 ... -
Poi处理Excel时公式不能更新的问题
2012-03-29 14:52 4436使用Poi处理Excel时,发现如果使用Poi编辑了某个单元格 ... -
大数据量导出Excel的方案 POI、JXL、FastExcel比较
2012-03-26 16:27 8466试共同条件: 数据总数 ... -
c3p0数据源配置文件详细配置 官方中文文档
2012-03-02 10:05 1333官方文档 :http://www.mchange.com/pr ... -
MyEclipse下远程调试liunx下的代码——转载
2012-02-02 15:56 967MyEclipse下远程调试liunx下的代码 在编译好的c ... -
poi操作Excel2007后打开老弹出提示框
2012-01-04 09:58 1664最近在写POI操作Excel2007的的代码,可是用POI操作 ... -
firefox和ie单元格自动换行-转载
2011-11-16 17:52 1411firefox和ie单元格自动换 ... -
div+css 兼容ie6 ie7 ie8 ie9和FireFox Chrome等浏览器方法——转载
2011-11-11 18:00 3044div+css 兼容ie6 ie7 ie8 ie9和FireF ... -
div强制换行和强制不换行
2011-11-10 21:46 1121div强制换行和强制不换行 1、强制不换行,同时以省略号结尾 ... -
让Flash乖乖躲到Div浮动层下去——转发
2011-10-28 14:38 935发现网站首页中因为放了好多Flash,结果把几个浮动的都挡住了 ... -
如何修改TortoiseSVN客户端的用户
2011-08-02 18:55 921今天用SVN时老提示403错误,可是我是有提交权限的,郁闷了N ... -
Property path [...] does not reference a collection
2011-07-18 11:19 6638criteria.add(Restrictions.or(Re ... -
第一次用Jodeclipse遇到的问题,求解???
2011-05-25 17:25 1219An error has occurred.See error ... -
通过Java获取酷6视频--转载
2011-04-09 17:38 844通过JAVA获取酷6视频,现在很多社会网站都有这个功能,用户输 ... -
IE下载excel,直接打开报错
2011-03-09 11:01 2971最近在做报表的下载,利用poi生成的excel报表。下 ... -
POI实现Excel插入图片
2011-03-08 16:14 2430POI的操作Excel时,不可避免有操作图片的处理。怎么插入图 ... -
隐藏横向滚动条
2011-02-15 14:42 1133今天刚找到一方法,可以完全解决隐藏横向滚动条问题,直接在页面中 ... -
js判断输入框中内容是否为空
2011-01-24 21:09 1614在js中如果直接引用"abc".trim( ...
相关推荐
采用java实现的常用hash算法归总。
工具类
Hash算法大全(java实现)参照.pdf
Hash算法大全(java实现)汇编.pdf
geohash基本原理是将地球理解为一个二维平面,将平面递归分解成更小的子块,每个子块在一定经纬度范围内拥有相同的编码。GeoHash将二维的经纬度转换成一维的字符串。
MurmurHash算法由Austin Appleby创建于2008年,现已应用到Hadoop、libstdc 、nginx、libmemcached,Redis,Memcached,Cassandra,HBase,Lucene等开源系统。2011年Appleby被Google雇佣,随后Google推出其变种的...
java_Hash算法大全
最快的排序算法 javahash实现-Java-哈希算法-最快的实现,排序算法数据结构
别人写的一个一致性hash的java实现,分享下
算法学习:Hash算法大全,Java代码
ConsistentHash 一致性hash算法的 java 和 C++ 实现
一个hash算法的工具类,里面包含了一些常用的hash算法
网上有很多geohash算法的实现,都是基于java或者php代码实现的,没有sql实现的版本,这里使用mysql简单实现了这个算法
1、解决案:排序+List 2、解决案:遍历+List 1、最好情况是只有个服务器节点的Hash值于带路由结点的Hash值,其 2、最坏情况是所有服务器节点的H
关于bin_sort、common、hash、red_black、quick_sort等算法的Java实现的源码,下载后可直接运行
murmurhash-java 这是Viliam Holub对快速非加密murmurhash2算法的一种实现。 它用Java编写,并以32位和64位版本实现。 如果您想了解最新的杂音世界,请查看Guava的类,该类具有murmur3和32位的实现。建造用maven构建...
常见算法及部分java实现。。。包括各种排序算法、红黑树、负载均衡算法、crc算法、摘要算法、对称非对称加密算法、一致性hash算法等等。。。
该文件包含了MD5的完整实现过程,采用java步步实现其过程
非常使用的 基于geohash 找一定范围内的 最近位置java代码
哈希计算工具 java-hash.7z