这是DJB2 hash算法,用途将一个字符串映射为一个整数,由Daniel J. Bernstein在1991年发明……
hash(unsigned char *str) { unsigned long hash = 5381; int c; while (c = *str++) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ return hash; }
介绍可以看这里
Written by Daniel J. Bernstein (also known as djb), this simple hash function dates back to 1991.
Hash functions have wide applications in computer science and in cryptography. They are used to map a potentially large amount of data to a number that represents it.
For example, the hash function from this code snippet mapsHello
to210676686969
, butHello!
to6952330670010
. Despite the fact there’s only one character different (the exclamation mark), the number returned is completely different.
本站所有内容均为互联网搜索引擎提供的公开搜索信息,本站不存储任何数据与内容,任何内容与数据均与本站无关,如有需要请联系相关搜索引擎包括但不限于百度,google,bing,sogou 等
© 2025 tinynews.org All Rights Reserved. 百科问答小站 版权所有