Skip to content

Commit

Permalink
Rewrote insertionSort to only require operator< (no >),
Browse files Browse the repository at this point in the history
and removed the unnecessary operators.
  • Loading branch information
hiker committed May 28, 2014
1 parent dd04c11 commit b18d7e7
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 81 deletions.
27 changes: 0 additions & 27 deletions src/addons/addon.hpp
Expand Up @@ -297,33 +297,6 @@ class Addon
return true;
} // operator<

// ------------------------------------------------------------------------
/** Compares two addons according to the sort order currently defined.
* Comparison is done for sorting in descending order.
* \param a The addon to compare this addon to.
*/
bool operator>(const Addon &a) const
{
switch(m_sort_order)
{
case SO_DEFAULT:
if(testStatus(AS_FEATURED) &&
!a.testStatus(AS_FEATURED)) return true;
if(!testStatus(AS_FEATURED) &&
a.testStatus(AS_FEATURED)) return false;
// Otherwise fall through to name comparison!
case SO_NAME:
// m_id is the lower case name
return m_id > a.m_id;
break;
case SO_DATE:
return m_date < a.m_date;
break;
} // switch
// Fix compiler warning.
return true;
} // operator>

}; // Addon


Expand Down
7 changes: 0 additions & 7 deletions src/config/player_profile.cpp
Expand Up @@ -266,11 +266,4 @@ bool PlayerProfile::operator<(const PlayerProfile &other)
} // operator<

// -----------------------------------------------------------------------------
/** \brief Needed for toggling sort order **/
bool PlayerProfile::operator>(const PlayerProfile &other)
{
return m_use_frequency > other.m_use_frequency;
} // operator>

// -----------------------------------------------------------------------------

1 change: 0 additions & 1 deletion src/config/player_profile.hpp
Expand Up @@ -116,7 +116,6 @@ class PlayerProfile : public NoCopy
void initRemainingData();
void incrementUseFrequency();
bool operator<(const PlayerProfile &other);
bool operator>(const PlayerProfile &other);
void raceFinished();
void saveSession(int user_id, const std::string &token);
void clearSession();
Expand Down
24 changes: 1 addition & 23 deletions src/online/server.hpp
Expand Up @@ -100,7 +100,7 @@ namespace Online{
break;
case SO_NAME:
// m_id is the lower case name
return m_name < server.getName();
return m_lower_case_name < server.m_lower_case_name;
break;
case SO_PLAYERS:
return m_current_players < server.getCurrentPlayers();
Expand All @@ -109,28 +109,6 @@ namespace Online{
return true;
} // operator<

// ------------------------------------------------------------------------
/** Compares two addons according to the sort order currently defined.
* Comparison is done for sorting in descending order.
* \param a The addon to compare this addon to.
*/
bool operator>(const Server &server) const
{
switch(m_sort_order)
{
case SO_SCORE:
return m_satisfaction_score > server.getScore();
break;
case SO_NAME:
return m_lower_case_name > server.getLowerCaseName();
break;
case SO_PLAYERS:
return m_current_players > server.getCurrentPlayers();
break;
} // switch
return true;
} // operator>

}; // Server
} // namespace Online

Expand Down
7 changes: 0 additions & 7 deletions src/race/race_manager.cpp
Expand Up @@ -555,13 +555,6 @@ namespace computeGPRanksData
(m_score == a.m_score && m_race_time < a.m_race_time) );
}

// --------------------------------------------------------------------
bool operator>(const SortData &a)
{
return ( (m_score < a.m_score) ||
(m_score == a.m_score && m_race_time > a.m_race_time) );
}

}; // SortData
} // namespace

Expand Down
13 changes: 0 additions & 13 deletions src/tracks/track.cpp
Expand Up @@ -170,19 +170,6 @@ bool Track::operator<(const Track &other) const
return other_is_locked;
} // operator<

//-----------------------------------------------------------------------------
bool Track::operator>(const Track &other) const
{
PlayerProfile *p = PlayerManager::getCurrentPlayer();
bool this_is_locked = p->isLocked(getIdent());
bool other_is_locked = p->isLocked(other.getIdent());
if(this_is_locked == other_is_locked)
{
return !(getSortName() < other.getSortName());
}
else
return this_is_locked;
}
//-----------------------------------------------------------------------------
/** Returns the name of the track, which is e.g. displayed on the screen.
\note this is the LTR name, invoke fribidi as needed. */
Expand Down
1 change: 0 additions & 1 deletion src/tracks/track.hpp
Expand Up @@ -616,7 +616,6 @@ class Track
float getDisplacementSpeed() const { return m_displacement_speed; }
float getCausticsSpeed() const { return m_caustics_speed; }
bool operator<(const Track &other) const;
bool operator>(const Track &other) const;
}; // class Track

#endif
4 changes: 2 additions & 2 deletions src/utils/ptr_vector.hpp
Expand Up @@ -277,7 +277,7 @@ class PtrVector
{
for(int j=(int)start; j<(int)m_contents_vector.size()-1; j++)
{
if(*(m_contents_vector[j])>*(m_contents_vector[j+1])) continue;
if(*(m_contents_vector[j+1])<*(m_contents_vector[j])) continue;
// Now search the proper place for m_contents_vector[j+1]
// in the sorted section contentsVectot[start:j]
TYPE* t=m_contents_vector[j+1];
Expand All @@ -286,7 +286,7 @@ class PtrVector
{
m_contents_vector[i] = m_contents_vector[i-1];
i--;
} while (i>start && *t>*(m_contents_vector[i-1]));
} while (i>start && *(m_contents_vector[i-1]) <*t);
m_contents_vector[i]=t;
}
}
Expand Down

0 comments on commit b18d7e7

Please sign in to comment.