Gathering detailed insights and metrics for imurmurhash
Gathering detailed insights and metrics for imurmurhash
Gathering detailed insights and metrics for imurmurhash
Gathering detailed insights and metrics for imurmurhash
An incremental implementation of MurmurHash3 for JavaScript
npm install imurmurhash
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
94 Stars
11 Commits
7 Forks
3 Watching
1 Branches
1 Contributors
Updated on 13 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-3.4%
8,837,232
Compared to previous day
Last week
2.9%
48,171,549
Compared to previous week
Last month
16.5%
194,877,184
Compared to previous month
Last year
18.1%
1,957,492,311
Compared to previous year
An incremental implementation of the MurmurHash3 (32-bit) hashing algorithm for JavaScript based on Gary Court's implementation with kazuyukitanimura's modifications.
This version works significantly faster than the non-incremental version if you need to hash many small strings into a single hash, since string concatenation (to build the single string to pass the non-incremental version) is fairly costly. In one case tested, using the incremental version was about 50% faster than concatenating 5-10 strings and then hashing.
To use iMurmurHash in the browser, download the latest version and include it as a script on your site.
1<script type="text/javascript" src="/scripts/imurmurhash.min.js"></script> 2<script> 3// Your code here, access iMurmurHash using the global object MurmurHash3 4</script>
To use iMurmurHash in Node.js, install the module using NPM:
1npm install imurmurhash
Then simply include it in your scripts:
1MurmurHash3 = require('imurmurhash');
1// Create the initial hash 2var hashState = MurmurHash3('string'); 3 4// Incrementally add text 5hashState.hash('more strings'); 6hashState.hash('even more strings'); 7 8// All calls can be chained if desired 9hashState.hash('and').hash('some').hash('more'); 10 11// Get a result 12hashState.result(); 13// returns 0xe4ccfe6b
Get 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:
1// Use the cached object, calling the function again will return the same 2// object (but reset, so the current state would be lost) 3hashState = MurmurHash3(); 4... 5 6// Create a new object that can be safely used however you wish. Calling the 7// function again will simply return a new state object, and no state loss 8// will occur, at the cost of creating more objects. 9hashState = new MurmurHash3();
Both methods can be mixed however you like if you have different use cases.
Incrementally add string to the hash. This can be called as many times as you want for the hash state object, including after a call to result()
. Returns this
so calls can be chained.
Get 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
.
1// Do the whole string at once 2MurmurHash3('this is a test string').result(); 3// 0x70529328 4 5// Do part of the string, get a result, then the other part 6var m = MurmurHash3('this is a'); 7m.result(); 8// 0xbfc4f834 9m.hash(' test string').result(); 10// 0x70529328 (same as above)
Reset the state object for reuse, optionally using the given seed (defaults to 0 like the constructor). Returns this
so calls can be chained.
Copyright (c) 2013 Gary Court, Jens Taylor
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/11 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More