collection-utils
Advanced tools
Comparing version
export declare const hashCodeInit = 17; | ||
export declare function hashString(str: string): number; | ||
export declare function addHashCode(acc: number, h: number): number; | ||
@@ -3,0 +4,0 @@ export declare function withDefault<T>(x: T | undefined, theDefault: T): T; |
@@ -11,4 +11,14 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const stringHash = require("string-hash"); | ||
exports.hashCodeInit = 17; | ||
// This function based on Java's string hashing. | ||
function hashString(str) { | ||
let hash = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
const chr = str.charCodeAt(i); | ||
hash = ((hash << 5) - hash) + chr; | ||
hash = hash & hash; // Convert to 32bit integer | ||
} | ||
return hash; | ||
} | ||
exports.hashString = hashString; | ||
function addHashCode(acc, h) { | ||
@@ -475,3 +485,3 @@ return (acc * 31 + (h | 0)) | 0; | ||
*values() { | ||
for (const [_h, [_k, v]] of this._map) { | ||
for (const [, [, v]] of this._map) { | ||
yield v; | ||
@@ -486,5 +496,2 @@ } | ||
} | ||
if (a === undefined || b === undefined || a === null || b === null) { | ||
return false; | ||
} | ||
if (typeof a.equals === "function" && typeof b.equals === "function") { | ||
@@ -529,3 +536,3 @@ return a.equals(b); | ||
if (typeof x === "string") | ||
return stringHash(x); | ||
return hashString(x); | ||
let h = exports.hashCodeInit; | ||
@@ -532,0 +539,0 @@ if (x === undefined) |
{ | ||
"name": "collection-utils", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"main": "dist/index.js", | ||
@@ -17,6 +17,2 @@ "types": "dist/index.d.ts", | ||
}, | ||
"dependencies": { | ||
"@types/string-hash": "^1.1.1", | ||
"string-hash": "^1.1.3" | ||
}, | ||
"files": [ | ||
@@ -23,0 +19,0 @@ "package.json", |
Sorry, the diff of this file is not supported yet
46222
33.99%0
-100%6
20%634
1.28%- Removed
- Removed
- Removed
- Removed