Skip to content

Commit b8785ed

Browse files
committed
Format
1 parent b0afb8f commit b8785ed

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/dict.mjs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function hashByReference(o) {
2525
referenceMap.set(o, hash);
2626
return hash;
2727
}
28+
2829
/**
2930
* merge two hashes in an order sensitive way
3031
* @param {number} a
@@ -34,6 +35,7 @@ function hashByReference(o) {
3435
function hashMerge(a, b) {
3536
return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0;
3637
}
38+
3739
/**
3840
* standard string hash popularised by java
3941
* @param {string} s
@@ -47,6 +49,7 @@ function hashString(s) {
4749
}
4850
return hash;
4951
}
52+
5053
/**
5154
* hash a number by converting to two integers and do some jumbling
5255
* @param {number} n
@@ -58,6 +61,7 @@ function hashNumber(n) {
5861
const j = tempDataView.getInt32(4);
5962
return Math.imul(0x45d9f3b, (i >> 16) ^ i) ^ j;
6063
}
64+
6165
/**
6266
* hash a BigInt by converting it to a string and hashing that
6367
* @param {BigInt} n
@@ -66,6 +70,7 @@ function hashNumber(n) {
6670
function hashBigInt(n) {
6771
return hashString(n.toString());
6872
}
73+
6974
/**
7075
* hash any js object
7176
* @param {any} o
@@ -113,6 +118,7 @@ function hashObject(o) {
113118
}
114119
return h;
115120
}
121+
116122
/**
117123
* hash any js value
118124
* @param {any} u
@@ -140,6 +146,7 @@ export function getHash(u) {
140146
return 0; // should be unreachable
141147
}
142148
}
149+
143150
/**
144151
* @template K,V
145152
* @typedef {ArrayNode<K,V> | IndexNode<K,V> | CollisionNode<K,V>} Node
@@ -172,6 +179,7 @@ const ENTRY = 0;
172179
const ARRAY_NODE = 1;
173180
const INDEX_NODE = 2;
174181
const COLLISION_NODE = 3;
182+
175183
/** @type {IndexNode<any,any>} */
176184
const EMPTY = {
177185
type: INDEX_NODE,
@@ -187,6 +195,7 @@ const EMPTY = {
187195
function mask(hash, shift) {
188196
return (hash >>> shift) & MASK;
189197
}
198+
190199
/**
191200
* Set only the Nth bit where N is the masked hash
192201
* @param {number} hash
@@ -196,6 +205,7 @@ function mask(hash, shift) {
196205
function bitpos(hash, shift) {
197206
return 1 << mask(hash, shift);
198207
}
208+
199209
/**
200210
* Count the number of 1 bits in a number
201211
* @param {number} x
@@ -209,6 +219,7 @@ function bitcount(x) {
209219
x += x >> 16;
210220
return x & 0x7f;
211221
}
222+
212223
/**
213224
* Calculate the array index of an item in a bitmap index node
214225
* @param {number} bitmap
@@ -218,6 +229,7 @@ function bitcount(x) {
218229
function index(bitmap, bit) {
219230
return bitcount(bitmap & (bit - 1));
220231
}
232+
221233
/**
222234
* Efficiently copy an array and set one value at an index
223235
* @template T
@@ -235,6 +247,7 @@ function cloneAndSet(arr, at, val) {
235247
out[at] = val;
236248
return out;
237249
}
250+
238251
/**
239252
* Efficiently copy an array and insert one value at an index
240253
* @template T
@@ -257,6 +270,7 @@ function spliceIn(arr, at, val) {
257270
}
258271
return out;
259272
}
273+
260274
/**
261275
* Efficiently copy an array and remove one value at an index
262276
* @template T
@@ -278,6 +292,7 @@ function spliceOut(arr, at) {
278292
}
279293
return out;
280294
}
295+
281296
/**
282297
* Create a new node containing two entries
283298
* @template K,V
@@ -308,9 +323,10 @@ function createNode(shift, key1, val1, key2hash, key2, val2) {
308323
key2hash,
309324
key2,
310325
val2,
311-
addedLeaf
326+
addedLeaf,
312327
);
313328
}
329+
314330
/**
315331
* @template T,K,V
316332
* @callback AssocFunction
@@ -377,7 +393,7 @@ function assocArray(root, shift, hash, key, val, addedLeaf) {
377393
array: cloneAndSet(
378394
root.array,
379395
idx,
380-
createNode(shift + SHIFT, node.k, node.v, hash, key, val)
396+
createNode(shift + SHIFT, node.k, node.v, hash, key, val),
381397
),
382398
};
383399
}
@@ -441,7 +457,7 @@ function assocIndex(root, shift, hash, key, val, addedLeaf) {
441457
array: cloneAndSet(
442458
root.array,
443459
idx,
444-
createNode(shift + SHIFT, nodeKey, node.v, hash, key, val)
460+
createNode(shift + SHIFT, nodeKey, node.v, hash, key, val),
445461
),
446462
};
447463
} else {
@@ -528,7 +544,7 @@ function assocCollision(root, shift, hash, key, val, addedLeaf) {
528544
hash,
529545
key,
530546
val,
531-
addedLeaf
547+
addedLeaf,
532548
);
533549
}
534550
/**
@@ -813,6 +829,7 @@ function forEach(root, fn) {
813829
forEach(item, fn);
814830
}
815831
}
832+
816833
/**
817834
* Extra wrapper to keep track of Dict size and clean up the API
818835
* @template K,V
@@ -833,6 +850,7 @@ export default class Dict {
833850
}
834851
return m;
835852
}
853+
836854
/**
837855
* @template K,V
838856
* @param {Map<K,V>} o
@@ -846,9 +864,11 @@ export default class Dict {
846864
});
847865
return m;
848866
}
867+
849868
static new() {
850869
return new Dict(undefined, 0);
851870
}
871+
852872
/**
853873
* @param {undefined | Node<K,V>} root
854874
* @param {number} size

src/gleam_stdlib.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ export function to_string(term) {
4747
}
4848

4949
export function float_to_string(float) {
50-
const string = float.toString().replace('+', '');
50+
const string = float.toString().replace("+", "");
5151
if (string.indexOf(".") >= 0) {
5252
return string;
5353
} else {
5454
const index = string.indexOf("e");
5555
if (index >= 0) {
56-
return string.slice(0, index) + '.0' + string.slice(index);
56+
return string.slice(0, index) + ".0" + string.slice(index);
5757
} else {
5858
return string + ".0";
5959
}
@@ -186,7 +186,7 @@ export function pop_grapheme(string) {
186186
}
187187

188188
export function pop_codeunit(str) {
189-
return [str.charCodeAt(0)|0, str.slice(1)]
189+
return [str.charCodeAt(0) | 0, str.slice(1)];
190190
}
191191

192192
export function lowercase(string) {
@@ -256,12 +256,15 @@ export function string_slice(string, idx, len) {
256256

257257
return result;
258258
} else {
259-
return string.match(/./gsu).slice(idx, idx + len).join("");
259+
return string
260+
.match(/./gsu)
261+
.slice(idx, idx + len)
262+
.join("");
260263
}
261264
}
262265

263266
export function string_codeunit_slice(str, from, length) {
264-
return str.slice(from, from + length)
267+
return str.slice(from, from + length);
265268
}
266269
export function crop_string(string, substring) {
267270
return string.substring(string.indexOf(substring));
@@ -305,7 +308,7 @@ const unicode_whitespaces = [
305308
const trim_start_regex = new RegExp(`^[${unicode_whitespaces}]*`);
306309
const trim_end_regex = new RegExp(`[${unicode_whitespaces}]*$`);
307310
const trim_regex = new RegExp(
308-
`^[${unicode_whitespaces}]*(.*?)[${unicode_whitespaces}]*$`
311+
`^[${unicode_whitespaces}]*(.*?)[${unicode_whitespaces}]*$`,
309312
);
310313

311314
export function trim(string) {
@@ -1014,4 +1017,3 @@ export function bit_array_starts_with(bits, prefix) {
10141017

10151018
return true;
10161019
}
1017-

0 commit comments

Comments
 (0)