Basic djb2 non-cypto hash function build with Babel and Webpack.
djb2
This algorithm (k=33) was first reported by dan bernstein many years ago in comp.lang.c. another version of this algorithm (now favored by bernstein) uses xor:
hash(i) = hash(i - 1) * 33 ^ str[i];
the magic of number 33 why it works better than many other constants, prime or not) has never been adequately explained.
unsigned long
hash(unsigned char *str)
{
unsigned long hash = 5381;
int c;
while (c = *str++)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
http://www.cse.yorku.ca/~oz/hash.html https://github.com/contra/djb2
- run
yarn
- Edit
package.json
default values like : name and version. - Change
README.md
- Add and edit content in
src/
andresources/
directories. - Write tests in
test/
directory.
npm test
- Inspect name and version in
package.json
, edit if necessary. - Run
npm run build
- Output will be placed in
dist/
directory, which can be published as NPM module.
- index.js size 614
- bundle size 4056
- factor 6.6