forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_hash.js
73 lines (66 loc) · 2.35 KB
/
caml_hash.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
var Caml_queue = require("./caml_queue.js");
var Caml_hash_primitive = require("./caml_hash_primitive.js");
var Caml_builtin_exceptions = require("./caml_builtin_exceptions.js");
function caml_hash(count, _, seed, obj) {
var hash = seed;
if (typeof obj === "number") {
var u = obj | 0;
hash = Caml_hash_primitive.caml_hash_mix_int(hash, (u + u | 0) + 1 | 0);
return Caml_hash_primitive.caml_hash_final_mix(hash);
} else if (typeof obj === "string") {
hash = Caml_hash_primitive.caml_hash_mix_string(hash, obj);
return Caml_hash_primitive.caml_hash_final_mix(hash);
} else {
var queue = /* record */[
/* length */0,
/* tail : None */0
];
var num = count;
Caml_queue.push(obj, queue);
num = num - 1 | 0;
while(queue[/* length */0] !== 0 && num > 0) {
var obj$1 = Caml_queue.unsafe_pop(queue);
if (typeof obj$1 === "number") {
var u$1 = obj$1 | 0;
hash = Caml_hash_primitive.caml_hash_mix_int(hash, (u$1 + u$1 | 0) + 1 | 0);
num = num - 1 | 0;
} else if (typeof obj$1 === "string") {
hash = Caml_hash_primitive.caml_hash_mix_string(hash, obj$1);
num = num - 1 | 0;
} else if (typeof obj$1 !== "boolean") {
if (typeof obj$1 !== "undefined") {
if (typeof obj$1 === "symbol") {
throw [
Caml_builtin_exceptions.assert_failure,
[
"caml_hash.ml",
72,
8
]
];
} else if (typeof obj$1 !== "function") {
var size = obj$1.length;
if (size !== undefined) {
var obj_tag = obj$1.tag | 0;
var tag = (size << 10) | obj_tag;
if (tag === 248) {
hash = Caml_hash_primitive.caml_hash_mix_int(hash, obj$1[1]);
} else {
hash = Caml_hash_primitive.caml_hash_mix_int(hash, tag);
var v = size - 1 | 0;
var block = v < num ? v : num;
for(var i = 0; i <= block; ++i){
Caml_queue.push(obj$1[i], queue);
}
}
}
}
}
}
};
return Caml_hash_primitive.caml_hash_final_mix(hash);
}
}
exports.caml_hash = caml_hash;
/* No side effect */