원래의 순서대로 키를 유지하면서 값을 정렬하는 더 빠른 방법을 찾고자합니다. 나는 부스트를 사용하는 것을 피하고 안정된 정렬 일 필요는 없다. 이것은 내가 생각해 낸 코드입니다. 작동하지만 느리고 비효율적입니다. 정렬이 완료된 후지도를 유지할 필요가 없습니다.원래 색인을 유지하면서 값을 정렬하는 더 빠른 방법
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<float,int> column_map;
column_record *matrix = new column_record[m*n];
for (int i=0; i<n; i++)
{
for (int j=0; j<m; j++)
{
column_map.insert(std::pair<float,int>(value[m*i+j],j));
}
int j = 0;
for (std::multimap<float,int>::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;
}
어쩌면 나는 눈이 나쁘지 만 배정 후에'matrix'가 설정되지 않았고'column'이 선언 된 곳을 보지 못했을 가능성이 높습니다. 덕분에 – Nobody