forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_queue.js
53 lines (47 loc) · 1.05 KB
/
caml_queue.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
'use strict';
function create() {
return /* record */[
/* length */0,
/* tail : None */0
];
}
function push(x, q) {
if (q[/* length */0] === 0) {
var cell = [];
cell[0] = x;
cell[1] = cell;
q[/* length */0] = 1;
q[/* tail */1] = cell;
return /* () */0;
} else {
var tail = q[/* tail */1];
var head = tail[/* next */1];
var cell$1 = /* record */[
/* content */x,
/* next */head
];
q[/* length */0] = q[/* length */0] + 1 | 0;
tail[/* next */1] = cell$1;
q[/* tail */1] = cell$1;
return /* () */0;
}
}
function unsafe_pop(q) {
q[/* length */0] = q[/* length */0] - 1 | 0;
var tail = q[/* tail */1];
var head = tail[/* next */1];
if (head === tail) {
q[/* tail */1] = /* None */0;
} else {
tail[/* next */1] = head[/* next */1];
}
return head[/* content */0];
}
function is_empty(q) {
return q[/* length */0] === 0;
}
exports.create = create;
exports.push = push;
exports.unsafe_pop = unsafe_pop;
exports.is_empty = is_empty;
/* No side effect */