mirror of
https://github.com/denoland/deno.git
synced 2024-12-29 02:29:06 -05:00
1 line
35 KiB
JSON
1 line
35 KiB
JSON
|
{"_id":"imurmurhash","_rev":"20-497dd666b1387aefe27697c48d45634b","name":"imurmurhash","description":"An incremental implementation of MurmurHash3","dist-tags":{"latest":"0.1.4"},"versions":{"0.0.1":{"name":"imurmurhash","version":"0.0.1","description":"An incremental implementation of MurmurHash3","homepage":"https://github.com/jensyt/imurmurhash-js","main":"imurmurhash.js","files":["imurmurhash.js","imurmurhash.min.js","package.json","README.md"],"repository":{"type":"git","url":"https://github.com/jensyt/imurmurhash-js"},"bugs":{"url":"https://github.com/jensyt/imurmurhash-js/issues"},"keywords":["murmur","murmurhash","murmurhash3","hash","incremental"],"author":{"name":"Jens Taylor","email":"jensyt@gmail.com","url":"https://github.com/homebrewing"},"license":"MIT","dependencies":{},"devDependencies":{},"engines":{"node":">=0.8.19"},"readme":"iMurmurHash.JS\n==============\n\nAn incremental implementation of the MurmurHash3 (32-bit) hashing algorithm for JavaScript based on [Gary Court's implementation](https://github.com/garycourt/murmurhash-js).\n\nInstallation\n------------\n\nTo use iMurmurHash in the browser, [download the latest version](https://raw.github.com/jensyt/imurmurhash-js/master/imurmurhash.min.js) and include it as a script on your site.\n\n```html\n<script type=\"text/javascript\" src=\"/scripts/imurmurhash.min.js\"></script>\n<script>\n// Your code here, access iMurmurHash using the global object MurmurHash3\n</script>\n```\n\n---\n\nTo use iMurmurHash in Node.js, install the module using NPM:\n\n```bash\nnpm install imurmurhash\n```\n\nThen simply include it in your scripts:\n\n```javascript\nMurmurHash3 = require('imurmurhash');\n```\n\nQuick Example\n-------------\n\n```javascript\n// Create the initial hash\nvar hashState = MurmurHash3('string');\n\n// Incrementally add text\nhashState.hash('more strings');\nhashState.hash('even more strings');\n\n// All calls can be chained if desired\nhashState.hash('and').hash('some').hash('more');\n\n// Get a result\nhashState.result();\n// returns 0x29d3f1e3\n```\n\nFunctions\n---------\n\n### MurmurHash3 ([string], [seed])\nGet a hash state object, optionally initialized with the given _string_ and _seed_. _Seed_ must be a positive integer if provided. Calling this function without the `new` keyword will return a cached state object that has been reset. This is safe to use as long as the object is only used from a single thread and no other hashes are created while operating on this one. If this constraint cannot be met, you can use `new` to create a new state object. For example:\n\n```javascript\n// Use the cached object, calling the function again will return the same\n// object (but reset, so the current state would be lost)\nhashState = MurmurHash3();\n...\n\n// Create a new object that can be safely used however you wish. Calling the\n// function again will simply return a new state object, and no state loss\n// will occur, at the cost of creating more objects.\nhashState = new MurmurHash3();\n```\n\nBoth methods can be mixed however you like if you have different use cases.\n\n---\n\n### MurmurHash3.prototype.hash (string)\nIncrementally add a _string_ to the hash. This can be called as many times as you want for the hash state object, including after a calls to `result()`. Returns `this` so calls can be chained.\n\n---\n\n### MurmurHash3.prototype.result ()\nGet the result of the hash as a 32-bit positive integer. This performs the tail and finalizer portions of the algorithm, but does not store the result in the state object. This means that it is perfectly safe to get results and then continue adding strings via `hash`.\n\n```javascript\n// Do the whole string at once\nMurmurHash3('this is a test string').result();\n// 0x70529328\n\n// Do part of the string, get a result, then the other part\nvar m = MurmurHash3('this is a');\nm.result();\n// 0xbfc4f834\nm.hash(' test string').result();\n// 0x70529328 (same as above)\n```\n\n---\n\n### MurmurHash3.prototype.reset (seed)\nReset the state object for reuse, optionally using the given _seed_ (defaul
|