`
hanyh
  • 浏览: 235336 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

DJP Hash

    博客分类:
  • php
阅读更多
HASH_OU_NUMS-->函数
		function hash_use($username)
	{
		$mask = pow(2, 32) - 1;
		$micId = 5381;
		$micChar = 0;
		for ($i = 0; $i < strlen($username); $i++)
		{
			$micId += ($micId << 5) + ord($username[$i]);
			if($micId < 0)
			{
				$micId += pow(2, 32);
			}
			$micId = $micId & $mask;
		}
		if ($micId < 0)
		{
			$sp_num = pow(2, 31) - 1;
			return ((($micId + $sp_num) % HASH_OU_NUMS) +
				$sp_num % HASH_OU_NUMS + 2) % HASH_OU_NUMS;
		}
		else
		{
			return $micId % HASH_OU_NUMS;
		}
	}

General Purpose Hash Function Algorithms
to algorithms hashing by wastepixel on Oct 20, 2006
The General Hash Functions Library has the following mix of additive and rotative general purpose string hashing algorithms.

* RS Hash Function
A simple hash function from Robert Sedgwicks Algorithms in C book. I've added some simple optimizations to the algorithm in order to speed up its hashing process.
* JS Hash Function
A bitwise hash function written by Justin Sobel
* PJW Hash Function
This hash algorithm is based on work by Peter J. Weinberger of AT&T Bell Labs. The book Compilers (Principles, Techniques and Tools) by Aho, Sethi and Ulman, recommends the use of hash functions that employ the hashing methodology found in this particular algorithm.
* ELF Hash Function
Similar to the PJW Hash function, but tweaked for 32-bit processors. Its the hash function widely used on most UNIX systems.
* BKDR Hash Function
This hash function comes from Brian Kernighan and Dennis Ritchie's book "The C Programming Language". It is a simple hash function using a strange set of possible seeds which all constitute a pattern of 31....31...31 etc, it seems to be very similar to the DJB hash function.
* SDBM Hash Function
This is the algorithm of choice which is used in the open source SDBM project. The hash function seems to have a good over-all distribution for many different data sets. It seems to work well in situations where there is a high variance in the MSBs of the elements in a data set.
* DJB Hash Function
An algorithm produced by Professor Daniel J. Bernstein and shown first to the world on the usenet newsgroup comp.lang.c. It is one of the most efficient hash functions ever published.
* DEK Hash Function
An algorithm proposed by Donald E. Knuth in The Art Of Computer Programming Volume 3, under the topic of sorting and search chapter 6.4.
* AP Hash Function
An algorithm produced by me Arash Partow. I took ideas from all of the above hash functions making a hybrid rotative and additive hash function algorithm based around four primes 3,5,7 and 11. There isn't any real mathematical analysis explaining why one should use this hash function instead of the others described above other than the fact that I tired to resemble the design as close as possible to a simple LFSR. An empirical result which demonstrated the distributive abilities of the hash algorithm was obtained using a hash-table with 100003 buckets, hashing The Project Gutenberg Etext of Webster's Unabridged Dictionary, the longest encountered chain length was 7, the average chain length was 2, the number of empty buckets was 4579.


generalhashfunction.h

#ifndef INCLUDE_GENERALHASHFUNCTION_CPP_H
#define INCLUDE_GENERALHASHFUNCTION_CPP_H


#include <string>


typedef unsigned int (*HashFunction)(const std::string&);


unsigned int RSHash  (const std::string& str);
unsigned int JSHash  (const std::string& str);
unsigned int PJWHash (const std::string& str);
unsigned int ELFHash (const std::string& str);
unsigned int BKDRHash(const std::string& str);
unsigned int SDBMHash(const std::string& str);
unsigned int DJBHash (const std::string& str);
unsigned int DEKHash (const std::string& str);
unsigned int APHash  (const std::string& str);


#endif



generalhashfunction.cc

#include "GeneralHashFunctions.h"

unsigned int RSHash(const std::string& str)
{
   unsigned int b    = 378551;
   unsigned int a    = 63689;
   unsigned int hash = 0;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash = hash * a + str[i];
      a    = a * b;
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of RS Hash Function */


unsigned int JSHash(const std::string& str)
{
   unsigned int hash = 1315423911;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash ^= ((hash << 5) + str[i] + (hash >> 2));
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of JS Hash Function */


unsigned int PJWHash(const std::string& str)
{
   unsigned int BitsInUnsignedInt = (unsigned int)(sizeof(unsigned int) * 8);
   unsigned int ThreeQuarters     = (unsigned int)((BitsInUnsignedInt  * 3) / 4);
   unsigned int OneEighth         = (unsigned int)(BitsInUnsignedInt / 8);
   unsigned int HighBits          = (unsigned int)(0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth);
   unsigned int hash              = 0;
   unsigned int test              = 0;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash = (hash << OneEighth) + str[i];

      if((test = hash & HighBits)  != 0)
      {
         hash = (( hash ^ (test >> ThreeQuarters)) & (~HighBits));
      }
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of  P. J. Weinberger Hash Function */


unsigned int ELFHash(const std::string& str)
{
   unsigned int hash = 0;
   unsigned int x    = 0;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash = (hash << 4) + str[i];
      if((x = hash & 0xF0000000L) != 0)
      {
         hash ^= (x >> 24);
         hash &= ~x;
      }
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of ELF Hash Function */


unsigned int BKDRHash(const std::string& str)
{
   unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
   unsigned int hash = 0;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash = (hash * seed) + str[i];
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of BKDR Hash Function */


unsigned int SDBMHash(const std::string& str)
{
   unsigned int hash = 0;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash = str[i] + (hash << 6) + (hash << 16) - hash;
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of SDBM Hash Function */


unsigned int DJBHash(const std::string& str)
{
   unsigned int hash = 5381;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash = ((hash << 5) + hash) + str[i];
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of DJB Hash Function */


unsigned int DEKHash(const std::string& str)
{
   unsigned int hash = static_cast<unsigned int>(str.length());

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash = ((hash << 5) ^ (hash >> 27)) ^ str[i];
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of DEK Hash Function */


unsigned int APHash(const std::string& str)
{
   unsigned int hash = 0;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash ^= ((i & 1) == 0) ? (  (hash <<  7) ^ str[i] ^ (hash >> 3)) :
                               (~((hash << 11) ^ str[i] ^ (hash >> 5)));
   }

   return (hash & 0x7FFFFFFF);
}
/* End Of AP Hash Function */

分享到:
评论

相关推荐

    DJP教学下的旅游法学教学论文.doc

    "DJP教学下的旅游法学教学论文" DJP教学模式是指学生利用学案的引导和帮助,在自主学习、探究学习内容、建构知识意义的基础上,通过同伴之间的交流和师生共同的评析,使学生获得对知识的深入理解,最终达到学会学习...

    DJP课堂教学模式的再认识.pdf

    DJP课堂教学模式的再认识.pdf

    matlab精度检验代码-JPDA:区分性联合概率MMD(DJP-MMD)的代码

    该存储库包含用于域自适应的简单但有效的区分联合概率MMD(DJP-MMD)的代码。 我们通过将其嵌入联合概率域适应(JPDA)框架来验证其性能。 下图显示了DJP-MMD和联合MMD之间的区别。 更多细节请看 与传统的MMD方法...

    Assignment_Prim.cs.txt.zip_Science For All_spanning tree

    In computer science, Prim s algorithm is a greedy algorithm that finds a minimum ... Therefore it is also sometimes called the DJP algorithm, the Jarník algorithm, or the Prim–Jarník algorithm.

    Desktop Java Pinger:免费的便携式跨平台图形化多Pinger,100%纯Java-开源

    DJP-免费的便携式跨平台桌面图形多pinger,100%纯Java。 本地和远程(到syslog服务器)日志支持。 最初,DJP使用ICMP进行ping操作,如果不可用,它将尝试使用TCP / echo检查主机。 使用标准OS ICMP数据包大小-Linux...

    mocknet-rust

    sudo docker run --net=host --privileged --entrypoint /workspace/indradb -v /tmp:/tmp -v /home/djp/indradb/target/debug:/workspace --name indradb -it -d ubuntu:18.04 用于启动server_main容器的命令: ...

    Prim算法 最小生成树

    普里姆算法(Prim算法),图论中的一种算法,可在加权连通图里搜索最小生成树。意即由此算法搜索到的边子集所构成的树中,不但...因此,在某些场合,普里姆算法又被称为DJP算法、亚尔尼克算法或普里姆-亚尔尼克算法。

    prim算法.cpp

    普里姆算法(Prim算法),图论中的一种算法,可在加权连通图里搜索最小生成树。意即由此算法搜索到的边子集所构成的树中,不但...因此,在某些场合,普里姆算法又被称为DJP算法、亚尔尼克算法或普里姆-亚尔尼克算法。

    C++实现普利姆算法(包含详细的算法介绍)

    在计算机科学中,普里姆(也称为Jarník's)算法是一种贪婪算法,它为加权的无向图找到一个最小生成树 。...因此,它有时也被称为Jarník算法,普里姆-jarník算法, 普里姆-迪克斯特拉算法或者DJP算法。

    2.1独立基础平法施工图的识读.pdf

    - DJJP和DJP:这是独立基础的类型代号,分别代表不同形状的基础,如DJJP表示阶形坡形独立基础,DJP表示阶形或坡形普通独立基础。 - 编号:用于区分同一工程中不同位置的基础,例如DJJ序号××××,表明这是某个...

    算法Prim.zip

    因此,在某些场合,普里姆算法又被称为DJP算法、亚尔尼克算法或普里姆-亚尔尼克算法。 2.算法简单描述 1).输入:一个加权连通图,其中顶点集合为V,边集合为E; 2).初始化:Vnew = {x},其中x为集合V中的任一节点...

    cuballoon:Cuda Miner for Deft(气球哈希)

    古巴CUDA矿工支持气球128/4学分cpuminer-multi,由tpruvot创作修改为气球128/4,由barrystyle创作最佳的气球,由Belgarion创作(接受捐款:(deft)dJP7aS2GVbmSKbHrS9aRFycdab5UNd4zxa) Beldaion编写的Cuda转换...

    精品课件(2021-2022)平法识图2——独立基础钢筋识图与计算.ppt

    例如,DJp02表示普通坡形独立基础,编号为2,450/400/300表示基础的三个台阶高度。配筋部分,如B:X16@150,Y16@200,表明底板底部的钢筋配置。 计算独立基础钢筋工程量时,需要考虑底部和顶部钢筋的不同情况。底部...

    GBase 8a MPP Cluster管理工具手册

    7. 索引与视图管理:介绍了创建和删除Hash索引、新建视图、打开视图、编写视图脚本、删除视图等操作,用户可以借助这些功能优化查询性能,提高数据检索效率。 8. 存储过程与函数管理:详述了如何新建、修改、编写...

    springies:沙盒模拟操纵弹簧质量组件

    作者: Thanh-ha Nguyen (tn32) Dennis Park (djp28) ##项目详情开始日期:2014 年 1 月 18 日 结束日期:2014 年 2 月 8 日 花费时间:40-50小时 [Github repo] ( ) ##什么是Springies? 操纵弹簧质量组件的沙箱...

    中达VFD变频器电流检测电路.doc

    电流互感器输出的信号经过J1*/DJ2端子进入DU1放大,然后通过DJP1/J1端子排传递到MCU主板。若J1*与DJ2脱离,放大器的同相输入端悬空,会导致输出端电压异常,进而触发过电流或接地故障报警。 2. 电流检测电路的模拟...

    独立基础的平法表示方法.pptx

    例如,DJj 和 DJp 分别代表矩形独立基础的角部和边部。在平面图上,会明确标注出各个尺寸,如(h1/h2),表示基础的高度分段。 2. **截面注写**:截面注写是通过在基础的横截面图上标注尺寸和配筋信息,包括基础的竖...

    车流量统计程序

    虽然提供的压缩包文件“djp”没有具体的扩展名,但根据上下文推测,这可能包含了程序的源代码、训练数据集、配置文件或其他相关资源。源代码可能采用Python、C++或Java等编程语言编写,使用开源库如OpenCV进行图像...

    数据融合matlab代码-model-data-fusion:DALEC模型和模型数据融合代码用于生成“通过并置观测和数据同化获得的典型中国森

    数据融合matlab代码模型数据融合 DALEC模型和模型数据融合代码用于生成“通过并置观测和数据同化...DJP,Chadwick MA。使用马尔可夫链蒙特卡洛(MCMC)与生态模型进行数据同化的入门。 Oecologia,2011,167(3):599-

    独立基础、条形基础、筏形基础及桩基承台归类.pdf

    独立基础的类型包括DJJ、DJP、BJJ和BJP。规范要求独立基础墙、柱插筋的弯钩长度不得小于6d,当基础厚度(hj)小于直锚长度(lae)时,应弯锚15d。如果插筋部分保护层厚度小于5d,应设置横向钢筋或箍筋,间距不小于...

Global site tag (gtag.js) - Google Analytics