Documentation API of the 'cern.colt.GenericPermuting' Java class
GenericPermuting
cern.colt

Class GenericPermuting



  • public class GenericPermutingextends Object
    Generically reorders (permutes) arbitrary shaped data (for example, an array, three arrays, a 2-d matrix, two linked lists) using an in-place swapping algorithm. Imagine having a couple of apples. For some reason you decide to reorder them. The green one before the red one. The pale one after the shiny one, etc. This class helps to do the job.

    This class swaps elements around, in a way that avoids stumbling over its own feet: Let before be the generic data before calling the reordering method. Let after be the generic data after calling the reordering method. Then there holds after[i] == before[indexes[i]].

    Similar to GenericSorting, this class has no idea what kind of data it is reordering. It can decide to swap the data at index a with the data at index b. It calls a user provided Swapper object that knows how to swap the data of these indexes.

    For convenience, some non-generic variants are also provided. Further a method to generate the p-th lexicographical permutation indexes.

    Example:

      Reordering  [A,B,C,D,E] with indexes [0,4,2,3,1] yields   [A,E,C,D,B]  In other words, in the reordered list, we first have the element at old index 0, then the one at old index 4, then the ones at old indexes 2,3,1.  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]. 

    Here are some example swappers:

     // a swapper knows how to swap two indexes (a,b)  // reordering an array Swapper swapper = new Swapper() {     public void swap(int a, int b) {         String tmp; // reordering String[]         // int tmp; // reordering int[]         tmp = array[a];         array[a] = array[b];         array[b] = tmp;     } };  // reordering a list Swapper swapper = new Swapper() {     public void swap(int a, int b) {         Object tmp;         tmp = list.get(a);         list.set(a, list.get(b));         list.set(b, tmp);     } };  // reordering the rows of a 2-d matrix (see cern.colt.matrix) Swapper swapper = new Swapper() {     public void swap(int a, int b) {         matrix.viewRow(a).swap(matrix.viewRow(b));     } };  // reordering the columns of a 2-d matrix Swapper swapper = new Swapper() {     public void swap(int a, int b) {         matrix.viewColumn(a).swap(matrix.viewColumn(b));     } }; 
    See Also:
    Swapper, GenericSorting

Warning: You cannot see the full API documentation of this class since the access to the DatMelt documentation for third-party Java classes is denied. Guests can only view jhplot Java API. To view the complete description of this class and its methods, please request the full DataMelt membership.

If you are already a full member, please login to the DataMelt member area before visiting this documentation.