初始化

This commit is contained in:
yziiy
2025-08-11 11:06:07 +08:00
parent 083bc37c00
commit 5607d11395
19772 changed files with 3108723 additions and 18 deletions

View File

@@ -0,0 +1 @@
/node_modules

View File

@@ -0,0 +1,22 @@
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.
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/

View File

@@ -0,0 +1,20 @@
{
"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": []
}

View File

@@ -0,0 +1,17 @@
"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;

View File

@@ -0,0 +1,27 @@
{
"name": "string-hash",
"version": "1.1.3",
"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"
}
}

View File

@@ -0,0 +1,13 @@
"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);
});
});