title: faster way to sort on value while retaining original index
body: <p>I'm hoping to get some help coming up with a faster way to do a sort on value while retaining a key on the original order.  I would prefer to avoid using boost and it does not need to be a stable sort.  This is the code I came up with, it works but is slow and inefficent.  I have no need to keep the map after the sort is complete.</p>
  
  <pre><code>struct column_record
  {
      int index;
      float value;
  };
  
  // sort each column on value while retaining index
  column_record *preprocess_matrix(float *value, int m, int n)
  {
      std::multimap&lt;float,int&gt; column_map;
      column_record *matrix = new column_record[m*n];
  
      for (int i=0; i&lt;n; i++)
      {
          for (int j=0; j&lt;m; j++)
          {
              column_map.insert(std::pair&lt;float,int&gt;(value[m*i+j],j));
          }
  
          int j = 0;
  
          for (std::multimap&lt;float,int&gt;::iterator it=column_map.begin(); it!=column_map.end(); it++)
          {
              matrix[m*i+j].index = (*it).second;
              matrix[m*i+j].value = (*it).first;
              j++;
          }
  
          column_map.clear();
      }
  
      return matrix;
  }
  </code></pre>