-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
523830e
commit ffe5e64
Showing
3 changed files
with
30 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** Jenkins one_at_a_time hash https://en.wikipedia.org/wiki/Jenkins_hash_function */ | ||
export const jenkinsHash = (s: string) => { | ||
let hash = 0; | ||
|
||
for (let i = 0; i < s.length; i++) { | ||
hash += s.charCodeAt(i); | ||
hash += hash << 10; | ||
hash ^= hash >>> 6; | ||
} | ||
|
||
hash += hash << 3; | ||
hash ^= hash >>> 11; | ||
hash += hash << 15; | ||
|
||
return hash; | ||
}; | ||
|
||
/** Java hashCode() i think */ | ||
export const hashCode = (s: string) => { | ||
let hash = 0; | ||
for (let i = 0; i < s.length; i++) { | ||
hash = (hash << 5) - hash + s.charCodeAt(i); | ||
hash |= 0; | ||
} | ||
|
||
return hash; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './hashCode'; | ||
export * from './luhnCheck'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters