Skip to content

Commit

Permalink
👕 refactor: Initial lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Dec 21, 2021
1 parent b859a6c commit 30c4284
Show file tree
Hide file tree
Showing 15 changed files with 503 additions and 1,143 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"pinst": "2.1.6",
"power-assert": "1.6.1",
"regenerator-runtime": "0.13.9",
"xo": "0.36.1"
"xo": "0.47.0"
},
"ava": {
"files": [
Expand Down Expand Up @@ -203,6 +203,7 @@
"xo": {
"prettier": true,
"rules": {
"no-bitwise": "off",
"unicorn/filename-case": [
"error",
{
Expand Down
39 changes: 8 additions & 31 deletions src/array/api/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
import sort from './sort.js';
import sortFloat32 from './sortFloat32.js';
import sortInt16 from './sortInt16.js';
import sortInt32 from './sortInt32.js';
import sortInt8 from './sortInt8.js';
import sortUint16 from './sortUint16.js';
import sortUint32 from './sortUint32.js';
import sortUint8 from './sortUint8.js';

/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
export default {
sort,
sortFloat32,
sortInt16,
sortInt32,
sortInt8,
sortUint16,
sortUint32,
sortUint8
};

export {
sort,
sortFloat32,
sortInt16,
sortInt32,
sortInt8,
sortUint16,
sortUint32,
sortUint8
};
export {default as sort} from './sort.js';
export {default as sortInt16} from './sortInt16.js';
export {default as sortFloat32} from './sortFloat32.js';
export {default as sortInt8} from './sortInt8.js';
export {default as sortInt32} from './sortInt32.js';
export {default as sortUint32} from './sortUint32.js';
export {default as sortUint16} from './sortUint16.js';
export {default as sortUint8} from './sortUint8.js';
1 change: 1 addition & 0 deletions src/array/api/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const sort = (k, M, tuples) => {
return tuples;
}

// eslint-disable-next-line unicorn/no-new-array
const output = new Array(N);
if (k >= 1) {
return sortFixedLengthTuples(k, M, tuples, output, 0, N);
Expand Down
4 changes: 2 additions & 2 deletions src/array/api/sortFloat32.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import sortUint32 from './sortUint32.js';
// http://www.codercorner.com/RadixSortRevisited.htm
// http://stereopsis.com/radix.html
const floatFlip = (f) => {
const mask = -(f >>> 31) | 0x80000000;
const mask = -(f >>> 31) | 0x80_00_00_00;
return f ^ mask;
};

const iFloatFlip = (f) => {
const mask = ((f >>> 31) - 1) | 0x80000000;
const mask = ((f >>> 31) - 1) | 0x80_00_00_00;
return f ^ mask;
};

Expand Down
4 changes: 2 additions & 2 deletions src/array/api/sortUint16.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const sortUint16 = (array) => {
const M = 2 ** 8;
// TODO avoid copying back and forth
const tuples = Array.prototype.map.call(array, (x) => [
(x & 0xff00) >>> 8,
(x & 0xff) >>> 0
(x & 0xff_00) >>> 8,
(x & 0xff) >>> 0,
]);
const output = sort(k, M, tuples);
return Array.prototype.map.call(output, ([c, d]) => ((c << 8) | d) >>> 0);
Expand Down
10 changes: 5 additions & 5 deletions src/array/api/sortUint32.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const sortUint32 = (array) => {
const M = 2 ** 8; // TODO another good option is k = 3 M = 2**11
// TODO avoid copying back and forth
const tuples = Array.prototype.map.call(array, (x) => [
(x & 0xff000000) >>> 24,
(x & 0xff0000) >>> 16,
(x & 0xff00) >>> 8,
(x & 0xff) >>> 0
(x & 0xff_00_00_00) >>> 24,
(x & 0xff_00_00) >>> 16,
(x & 0xff_00) >>> 8,
(x & 0xff) >>> 0,
]);
const output = sort(k, M, tuples);
return Array.prototype.map.call(
output,
([a, b, c, d]) => ((a << 24) | (b << 16) | (c << 8) | d) >>> 0
([a, b, c, d]) => ((a << 24) | (b << 16) | (c << 8) | d) >>> 0,
);
};

Expand Down
1 change: 1 addition & 0 deletions src/array/core/reset.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fill from './fill.js';

const reset = (array, i, j) => fill(array, 0, i, j);
export default reset;
29 changes: 3 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
import {
export {
sort,
sortFloat32,
sortInt16,
sortInt32,
sortInt8,
sortUint16,
sortUint32,
sortUint8
} from './array/api/index.js';

/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
export default {
sort,
sortFloat32,
sortInt16,
sortInt32,
sortInt8,
sortUint16,
sortUint32,
sortUint8
};

export {
sort,
sortFloat32,
sortInt16,
sortInt32,
sortInt8,
sortUint16,
sortUint8,
sortUint32,
sortUint8
};
} from './array/api/index.js';
6 changes: 4 additions & 2 deletions test/_old/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export function nodes(lsb, head, hi, lo, si, sj) {

while (head !== null) {
if (lsb(head.value, si) === 0) {
_lo = _lo.next = head;
_lo.next = head;
_lo = head;
} else {
_hi = _hi.next = head;
_hi.next = head;
_hi = head;
}

head = head.next;
Expand Down
12 changes: 6 additions & 6 deletions test/src/api/sort.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import {AssertionError} from 'assert';
import test from 'ava';
import {list} from '@iterable-iterator/list';
import {all} from '@iterable-iterator/reduce';
import {map} from '@iterable-iterator/map';
Expand Down Expand Up @@ -48,7 +48,7 @@ test(throws, 2, 2, [[1], [0]]);
test(throws, 3, 3, [
[2, 1, 3],
[3, 2, 1],
[1, 2, 3]
[1, 2, 3],
]);

// Degenerates to counting sort
Expand All @@ -59,14 +59,14 @@ test(singletons, 3, [0, 2, 1]);
test(limbs, 3, 3, [
[2, 1, 0],
[0, 2, 1],
[1, 2, 0]
[1, 2, 0],
]);

// Custom radix
test(limbs, 3, 4, [
[2, 1, 3],
[3, 2, 1],
[1, 2, 3]
[1, 2, 3],
]);

test('Wikipedia example', limbs, 3, 10, [
Expand All @@ -77,7 +77,7 @@ test('Wikipedia example', limbs, 3, 10, [
[0, 0, 2],
[0, 2, 4],
[8, 0, 2],
[0, 6, 6]
[0, 6, 6],
]);

// Variable tuple length
Expand All @@ -89,5 +89,5 @@ test(limbs, -1, 10, [
[2],
[8, 0, 2],
[2],
[6, 6]
[6, 6],
]);
4 changes: 2 additions & 2 deletions test/src/api/sortInt16.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ test(macro, [1, -2, -3, 4]);

const N = 1 << 17;
const longShuffledInput = list(
Int16Array.from(range(Math.trunc(-N / 2), Math.trunc(N / 2)))
Int16Array.from(range(Math.trunc(-N / 2), Math.trunc(N / 2))),
);
shuffle(longShuffledInput, 0, N);
test(macro, longShuffledInput);

const longRandomInput = list(
map(() => randrange(-(2 ** 15), 2 ** 15), range(N))
map(() => randrange(-(2 ** 15), 2 ** 15), range(N)),
);
test(macro, longRandomInput);
2 changes: 1 addition & 1 deletion test/src/api/sortInt32.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ shuffle(longShuffledInput, 0, N);
test(macro, longShuffledInput);

const longRandomInput = list(
map(() => randrange(-(2 ** 31), 2 ** 31), range(N))
map(() => randrange(-(2 ** 31), 2 ** 31), range(N)),
);
test(macro, longRandomInput);
2 changes: 1 addition & 1 deletion test/src/api/sortInt8.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test(macro, [1, -2, -3, 4]);

const N = 1 << 17;
const longShuffledInput = list(
Int8Array.from(range(Math.trunc(-N / 2), Math.trunc(N / 2)))
Int8Array.from(range(Math.trunc(-N / 2), Math.trunc(N / 2))),
);
shuffle(longShuffledInput, 0, N);
test(macro, longShuffledInput);
Expand Down
6 changes: 3 additions & 3 deletions test/src/api/stability.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const isStable = (t, k, M, data) => {
const repr = (data) =>
data.length >= 20
? `[${JSON.stringify(data.slice(0, 9)).slice(1, -1)},..,${JSON.stringify(
data.slice(-9)
data.slice(-9),
).slice(1, -1)}]`
: JSON.stringify(data);

Expand All @@ -38,11 +38,11 @@ test(
isStable,
1,
1,
list(map(([a, b]) => [b, a], enumerate(nrepeat(0, 1000))))
list(map(([a, b]) => [b, a], enumerate(nrepeat(0, 1000)))),
);
test(
isStable,
2,
2,
list(map((i) => [randint(0, 2), randint(0, 2), i], range(1000)))
list(map((i) => [randint(0, 2), randint(0, 2), i], range(1000))),
);
Loading

0 comments on commit 30c4284

Please sign in to comment.