Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darkskyapp/string-hash
Fast string hashing function for Node.JS.
https://github.com/darkskyapp/string-hash
Last synced: about 2 months ago
JSON representation
Fast string hashing function for Node.JS.
- Host: GitHub
- URL: https://github.com/darkskyapp/string-hash
- Owner: darkskyapp
- Archived: true
- Created: 2012-10-09T17:37:50.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2020-04-24T12:43:04.000Z (over 4 years ago)
- Last Synced: 2024-05-15T13:09:13.248Z (4 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 309
- Watchers: 4
- Forks: 33
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
string-hash
===========A fast string hashing function for Node.JS. The particular algorithm is quite
similar to `djb2`, by Dan Bernstein and available
[here](http://www.cse.yorku.ca/~oz/hash.html). Differences include iterating
over the string *backwards* (as that is faster in JavaScript) and using the XOR
operator instead of the addition operator (as described at that page and
because it obviates the need for modular arithmetic in JavaScript).The hashing function returns a number between 0 and 4294967295 (inclusive).
Thanks to [cscott](https://github.com/cscott) for reminding us how integers
work in JavaScript.Example
-------`npm install string-hash` or `yarn add string-hash`, then:
```
const stringHash = require("string-hash");
console.log(stringHash("foo")); // prints "193420387"
```Note that the return value is always an unsigned, 32-bit integer.
License
-------To the extend possible by law, The Dark Sky Company, LLC has [waived all
copyright and related or neighboring rights][cc0] to this library.[cc0]: http://creativecommons.org/publicdomain/zero/1.0/