optimize SortSongPointerArrayByGrade
This commit is contained in:
+17
-4
@@ -1387,14 +1387,17 @@ void SortSongPointerArrayByBPM( vector<Song*> &arraySongPointers )
|
|||||||
sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongPointersByBPM );
|
sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongPointersByBPM );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct GradeCnt { int n[NUM_GRADES]; };
|
||||||
|
static map<Song *, GradeCnt> NumNotesWithGrade;
|
||||||
|
|
||||||
bool CompareSongPointersByGrade(const Song *pSong1, const Song *pSong2)
|
bool CompareSongPointersByGrade(const Song *pSong1, const Song *pSong2)
|
||||||
{
|
{
|
||||||
for( int i=NUM_GRADES; i>GRADE_NO_DATA; i-- )
|
const GradeCnt &cnt1=NumNotesWithGrade[(Song *) pSong1];
|
||||||
|
const GradeCnt &cnt2=NumNotesWithGrade[(Song *) pSong2];
|
||||||
|
for( int i=NUM_GRADES-1; i>GRADE_NO_DATA; i-- )
|
||||||
{
|
{
|
||||||
Grade g = (Grade)i;
|
const int iCount1 = cnt1.n[i];
|
||||||
int iCount1 = pSong1->GetNumNotesWithGrade( g );
|
const int iCount2 = cnt2.n[i];
|
||||||
int iCount2 = pSong2->GetNumNotesWithGrade( g );
|
|
||||||
|
|
||||||
if( iCount1 > iCount2 )
|
if( iCount1 > iCount2 )
|
||||||
return true;
|
return true;
|
||||||
@@ -1407,6 +1410,16 @@ bool CompareSongPointersByGrade(const Song *pSong1, const Song *pSong2)
|
|||||||
|
|
||||||
void SortSongPointerArrayByGrade( vector<Song*> &arraySongPointers )
|
void SortSongPointerArrayByGrade( vector<Song*> &arraySongPointers )
|
||||||
{
|
{
|
||||||
|
for(unsigned i = 0; i < arraySongPointers.size(); ++i)
|
||||||
|
{
|
||||||
|
GradeCnt cnt;
|
||||||
|
memset( cnt.n, 0, sizeof(cnt.n) );
|
||||||
|
|
||||||
|
Song *pSong = arraySongPointers[i];
|
||||||
|
for( int g=NUM_GRADES-1; g>GRADE_NO_DATA; g-- )
|
||||||
|
cnt.n[g] = pSong->GetNumNotesWithGrade( (Grade)g );
|
||||||
|
NumNotesWithGrade[pSong] = cnt;
|
||||||
|
}
|
||||||
sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongPointersByGrade );
|
sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongPointersByGrade );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user