array-rearrange
Advanced tools
Comparing version 2.2.0 to 2.2.1
24
index.js
@@ -13,3 +13,3 @@ 'use strict' | ||
if (arr.length !== index.length * stride) { | ||
if (arr.length !== n * stride) { | ||
throw Error('Bad length of index array') | ||
@@ -28,6 +28,10 @@ } | ||
for (var start = 0; start < n; start++) { | ||
let currId = start | ||
let pickId = index[currId] | ||
let currId, pickId = index[start] | ||
if (start === pickId) continue | ||
while (pickId !== start) { | ||
currId = pickId | ||
pickId = index[currId] | ||
let v = arr[pickId] | ||
@@ -38,6 +42,3 @@ arr[pickId] = arr[currId] | ||
index[currId] = currId | ||
currId = pickId | ||
pickId = index[currId] | ||
} | ||
index[currId] = currId | ||
} | ||
@@ -48,6 +49,10 @@ } | ||
for (var start = 0; start < n; start++) { | ||
let currId = start | ||
let pickId = index[currId] | ||
let currId, pickId = index[start] | ||
if (start === pickId) continue | ||
while (pickId !== start) { | ||
currId = pickId | ||
pickId = index[currId] | ||
for (var j = 0; j < stride; j++) { | ||
@@ -60,6 +65,3 @@ var value = arr[pickId * stride + j]; | ||
index[currId] = currId | ||
currId = pickId | ||
pickId = index[currId] | ||
} | ||
index[currId] = currId | ||
@@ -66,0 +68,0 @@ } |
{ | ||
"name": "array-rearrange", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Rearrange array elements by index array", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
11
test.js
@@ -25,3 +25,12 @@ 'use strict' | ||
console.time(1) | ||
reorder(a, idx) | ||
reorder(a, idx.slice()) | ||
console.timeEnd(1) | ||
let _a = new Float64Array(a) | ||
console.time(2) | ||
let b = new Float64Array(N) | ||
for (let i = 0; i < N; i++) { | ||
b[i] = a[idx[i]] | ||
} | ||
_a.set(b) | ||
console.timeEnd(2) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7240
117