FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
EmulatorJS/data/src/utils.js at main · allancoding/EmulatorJS · GitHub
allancoding
/
EmulatorJS
Public
forked from
EmulatorJS/EmulatorJS
Notifications
You must be signed in to change notification settings
Fork
1
Star
4
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
EmulatorJS
/
data
/
src
/
utils.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (46 loc) · 1.67 KB
Breadcrumbs
EmulatorJS
/
data
/
src
/
utils.js
Copy path
File metadata and controls
49 lines (46 loc) · 1.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* EJS Utility Functions
*/
/**
* Computes a simple hash of the given data array.
*
@param
{
Uint8Array
} dataArray
*
@returns
{
number
} The computed hash.
*/
export
function
simpleHash
(
dataArray
)
{
let
hash
=
0
;
for
(
let
i
=
0
;
i
<
dataArray
.
length
;
i
++
)
{
hash
=
(
(
hash
<<
5
)
-
hash
+
dataArray
[
i
]
)
&
0xffffffff
;
}
return
hash
;
}
/**
* Cyrb53 hash function adapted for buffers.
*
@param
{
*
} charBuffer
*
@param
{
*
} seed
*
@returns
{
string
} Hexadecimal representation of the hash.
*/
export
async
function
cyrb53
(
charBuffer
,
seed
=
0
)
{
// https://stackoverflow.com/questions/7616461
// Modified to accept a buffer instead of a string and return hex instead of an int
let
h1
=
0xdeadbeef
^
seed
,
h2
=
0x41c6ce57
^
seed
;
for
(
let
i
=
0
,
ch
;
i
<
charBuffer
.
length
;
i
++
)
{
ch
=
charBuffer
[
i
]
;
h1
=
Math
.
imul
(
h1
^
ch
,
2654435761
)
;
h2
=
Math
.
imul
(
h2
^
ch
,
1597334677
)
;
}
h1
=
Math
.
imul
(
h1
^
(
h1
>>>
16
)
,
2246822507
)
;
h1
^=
Math
.
imul
(
h2
^
(
h2
>>>
13
)
,
3266489909
)
;
h2
=
Math
.
imul
(
h2
^
(
h2
>>>
16
)
,
2246822507
)
;
h2
^=
Math
.
imul
(
h1
^
(
h1
>>>
13
)
,
3266489909
)
;
// Cyrb53 is a 53-bit hash; we need 14 hex characters to represent it, and the first char will
// always be 0 or 1 (since it is only 1 bit)
return
(
4294967296
*
(
2097151
&
h2
)
+
(
h1
>>>
0
)
)
.
toString
(
16
)
.
padStart
(
14
,
"0"
)
;
}
/**
* Generate a random GUID string.
*
@returns
{
string
} A GUID in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
*/
export
function
guid
(
)
{
const
s4
=
(
)
=>
(
(
(
1
+
Math
.
random
(
)
)
*
0x10000
)
|
0
)
.
toString
(
16
)
.
substring
(
1
)
;
return
s4
(
)
+
s4
(
)
+
"-"
+
s4
(
)
+
"-"
+
s4
(
)
+
"-"
+
s4
(
)
+
"-"
+
s4
(
)
+
s4
(
)
+
s4
(
)
;
}
Back
|
FazBrowse Home
|
New Git URL