Skip to content

Commit 64920d1

Browse files
✨ feat: Implement sortUint32.
1 parent 5996806 commit 64920d1

24 files changed

+61
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"transform-remove-console",
2828
{
2929
"exclude": [
30-
"debug",
3130
"log",
3231
"error",
3332
"warn"
@@ -82,6 +81,7 @@
8281
"devDependencies": {
8382
"@aureooms/js-compare": "^1.4.8",
8483
"@aureooms/js-itertools": "^4.1.0",
84+
"@aureooms/js-random": "^2.0.0",
8585
"@babel/cli": "7.11.6",
8686
"@babel/core": "7.11.6",
8787
"@babel/preset-env": "7.11.5",

src/array/sort.js renamed to src/array/api/sort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from 'assert';
2-
import sortFixedLengthTuples from './sortFixedLengthTuples';
3-
import sortArbitraryTuples from './sortArbitraryTuples';
2+
import sortFixedLengthTuples from '../core/sortFixedLengthTuples';
3+
import sortArbitraryTuples from '../core/sortArbitraryTuples';
44

55
const sort = (k, M, tuples) => {
66
assert(Number.isInteger(k));

src/array/api/sortUint32.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sort from './sort';
2+
3+
const sortUint32 = (array) => {
4+
const k = 4; // TODO make it depend on array.length
5+
const M = 256;
6+
// TODO avoid copying back and forth
7+
const tuples = Array.prototype.map.call(array, (x) => [
8+
(x & 0xff000000) >>> 24,
9+
(x & 0xff0000) >>> 16,
10+
(x & 0xff00) >>> 8,
11+
(x & 0xff) >>> 0
12+
]);
13+
const output = sort(k, M, tuples);
14+
return Array.prototype.map.call(
15+
output,
16+
([a, b, c, d]) => ((a << 24) | (b << 16) | (c << 8) | d) >>> 0
17+
);
18+
};
19+
20+
export default sortUint32;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)