-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathbelt_MutableStack.js
138 lines (118 loc) · 2.05 KB
/
belt_MutableStack.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'use strict';
let Caml_option = require("./caml_option.js");
function make() {
return {
root: undefined
};
}
function clear(s) {
s.root = undefined;
}
function copy(s) {
return {
root: s.root
};
}
function push(s, x) {
s.root = {
head: x,
tail: s.root
};
}
function topUndefined(s) {
let x = s.root;
if (x !== undefined) {
return x.head;
}
}
function top(s) {
let x = s.root;
if (x !== undefined) {
return Caml_option.some(x.head);
}
}
function isEmpty(s) {
return s.root === undefined;
}
function popUndefined(s) {
let x = s.root;
if (x !== undefined) {
s.root = x.tail;
return x.head;
}
}
function pop(s) {
let x = s.root;
if (x !== undefined) {
s.root = x.tail;
return Caml_option.some(x.head);
}
}
function size(s) {
let x = s.root;
if (x !== undefined) {
let _x = x;
let _acc = 0;
while (true) {
let acc = _acc;
let x$1 = _x;
let x$2 = x$1.tail;
if (x$2 === undefined) {
return acc + 1 | 0;
}
_acc = acc + 1 | 0;
_x = x$2;
continue;
};
} else {
return 0;
}
}
function forEachU(s, f) {
let _s = s.root;
while (true) {
let s$1 = _s;
if (s$1 === undefined) {
return;
}
f(s$1.head);
_s = s$1.tail;
continue;
};
}
function forEach(s, f) {
forEachU(s, (function (x) {
f(x);
}));
}
function dynamicPopIterU(s, f) {
while (true) {
let match = s.root;
if (match === undefined) {
return;
}
s.root = match.tail;
f(match.head);
continue;
};
}
function dynamicPopIter(s, f) {
dynamicPopIterU(s, (function (x) {
f(x);
}));
}
exports.make = make;
exports.clear = clear;
exports.copy = copy;
exports.push = push;
exports.popUndefined = popUndefined;
exports.pop = pop;
exports.topUndefined = topUndefined;
exports.top = top;
exports.isEmpty = isEmpty;
exports.size = size;
exports.forEachU = forEachU;
exports.forEach = forEach;
exports.dynamicPopIterU = dynamicPopIterU;
exports.dynamicPopIter = dynamicPopIter;
/* No side effect */