com.csource.common.Hash Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wichell-common Show documentation
Show all versions of wichell-common Show documentation
common project com.wichell.wichell jar
The newest version!
/*
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
* General Public License (LGPL).
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
*/
package com.csource.common;
/**
* name(key) and value pair model
* @author Happy Fish / YuQing
* @version Version 1.04
*/
public class Hash
{
protected Hash()
{
}
public static int PJWHash(byte[] key)
{
return PJWHash(key, 0, key.length);
}
public static int PJWHash(byte[] key, int offset, int length)
{
final int BitsInUnignedInt = (int)(4 * 8);
final int ThreeQuarters = (int)((BitsInUnignedInt * 3) / 4);
final int OneEighth = (int)(BitsInUnignedInt / 8);
final int HighBits = (int)(0xFFFFFFFF) <<
(BitsInUnignedInt - OneEighth);
int hash;
int test;
hash = 0;
for (int i=offset; i 0 ? key[i] : 256 + key[i]);
if ((test = hash & HighBits) != 0)
{
hash = ((hash ^ (test >> ThreeQuarters)) & (~HighBits));
}
}
return hash;
}
public static int Time33Hash(byte[] key)
{
return Time33Hash(key, 0, key.length);
}
public static int Time33Hash(byte[] key, int offset, int length)
{
int hash;
hash = 0;
for (int i=offset; i= 0 ? key[i] : 256 + key[i]);
}
return hash;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy