pax_global_header00006660000000000000000000000064134553572510014524gustar00rootroot0000000000000052 comment=cb38ab492aba198b9658b286bb2391278bb6992b string-hash-1.1.3/000077500000000000000000000000001345535725100137555ustar00rootroot00000000000000string-hash-1.1.3/.gitignore000066400000000000000000000000161345535725100157420ustar00rootroot00000000000000/node_modules string-hash-1.1.3/.travis.yml000066400000000000000000000001141345535725100160620ustar00rootroot00000000000000language: node_js node_js: - '6' cache: directories: - node_modules string-hash-1.1.3/README.md000066400000000000000000000021031345535725100152300ustar00rootroot00000000000000string-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/ string-hash-1.1.3/component.json000066400000000000000000000005301345535725100166500ustar00rootroot00000000000000{ "name": "string-hash", "repo": "darkskyapp/string-hash", "description": "fast string hashing function", "version": "1.1.1", "keywords": [ "string", "hashing" ], "dependencies": {}, "development": { "mocha": "1.3.x" }, "license": "CC0", "main": "index.js", "scripts": [ "index.js" ], "remotes": [] }string-hash-1.1.3/index.js000066400000000000000000000006301345535725100154210ustar00rootroot00000000000000"use strict"; function hash(str) { var hash = 5381, i = str.length; while(i) { hash = (hash * 33) ^ str.charCodeAt(--i); } /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed * integers. Since we want the results to be always positive, convert the * signed int to an unsigned by doing an unsigned bitshift. */ return hash >>> 0; } module.exports = hash; string-hash-1.1.3/package.json000066400000000000000000000007561345535725100162530ustar00rootroot00000000000000{ "name": "string-hash", "version": "1.1.4", "description": "fast string hashing function", "license": "CC0-1.0", "keywords": [ "string", "hashing" ], "author": { "name": "The Dark Sky Company", "email": "developer@darksky.net" }, "repository": { "type": "git", "url": "git://github.com/darkskyapp/string-hash.git" }, "main": "./index", "dependencies": { }, "devDependencies": { "mocha": "*" }, "scripts": { "test": "mocha" } } string-hash-1.1.3/test.js000066400000000000000000000005701345535725100152740ustar00rootroot00000000000000"use strict"; var assert = require("assert"), hash = require("./"); describe("hash", function() { it("should hash \"Mary had a little lamb.\" to 1766333550", function() { assert.equal(hash("Mary had a little lamb."), 1766333550); }); it("should hash \"Hello, world!\" to 343662184", function() { assert.equal(hash("Hello, world!"), 343662184); }); });