Generically reorders arbitrary shaped generic data g such that g[i] == g[indexes[i]]. (The
generic data may be one array, a 2-d matrix, two linked lists or whatever). This class swaps elements around, in a
way that avoids stumbling over its own feet. Example:
Reordering
[A,B,C,D,E] with indexes [0,4,2,3,1] yields
[A,E,C,D,B]
In other words g[0]<--g[0], g[1]<--g[4], g[2]<--g[2], g[3]<--g[3], g[4]<--g[1].
Reordering
[A,B,C,D,E] with indexes [0,4,1,2,3] yields
[A,E,B,C,D]
In other words g[0]<--g[0], g[1]<--g[4], g[2]<--g[1], g[3]<--g[2], g[4]<--g[3].
- Parameters:
indexes
- the permutation indexes.swapper
- an object that knows how to swap two indexes a,b.work1
- some working storage, must satisfy work1.length >= indexes.length; set work1==null
if you don't care about performance.work2
- some working storage, must satisfy work2.length >= indexes.length; set work2==null
if you don't care about performance.