Skip to content

Commit

Permalink
use unordered maps for string keyed scores
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed May 3, 2017
1 parent a09e150 commit 279150b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/ChartScores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void ScoresAtRate::AddScore(HighScore& hs) {
vector<string> ScoresAtRate::GetSortedKeys() {
map<float, string, greater<float>> tmp;
vector<string> o;
FOREACHM(string, HighScore, scores, i)
FOREACHUM(string, HighScore, scores, i)
tmp.emplace(i->second.GetWifeScore(), i->first);
FOREACHM(float, string, tmp, j)
o.emplace_back(j->second);
Expand Down Expand Up @@ -92,7 +92,7 @@ HighScore* PlayerScores::GetChartPBUpTo(string& ck, float& rate) {

void PlayerScores::SortTopSSRPtrs(Skillset ss) {
TopSSRs[ss].clear();
FOREACHM(string, ScoresForChart, pscores, i) {
FOREACHUM(string, ScoresForChart, pscores, i) {
if (!IsChartLoaded(i->first))
continue;
vector<HighScore*> pbs = i->second.GetAllPBPtrs();
Expand Down Expand Up @@ -150,7 +150,7 @@ XNode* ScoresAtRate::CreateNode(const int& rate) const {
o->AppendAttr("BestGrade", GradeToString(bestGrade));
o->AppendAttr("Rate", rs);

FOREACHM_CONST(string, HighScore, scores, i)
FOREACHUM_CONST(string, HighScore, scores, i)
o->AppendChild(i->second.CreateEttNode());

return o;
Expand All @@ -169,7 +169,7 @@ XNode * ScoresForChart::CreateNode(const string& ck) const {
XNode * PlayerScores::CreateNode() const {
XNode* o = new XNode("PlayerScores");

FOREACHM_CONST(string, ScoresForChart, pscores, ch)
FOREACHUM_CONST(string, ScoresForChart, pscores, ch)
o->AppendChild(ch->second.CreateNode(ch->first));

return o;
Expand Down
5 changes: 3 additions & 2 deletions src/ChartScores.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Grade.h"
#include "GameConstantsAndTypes.h"
#include <map>
#include <unordered_map>



Expand All @@ -18,7 +19,7 @@ struct ScoresAtRate
vector<string> GetSortedKeys();

void PushSelf(lua_State *L);
map<string, HighScore> scores;
unordered_map<string, HighScore> scores;

XNode* CreateNode(const int& rate) const;
void LoadFromNode(const XNode* node, const RString& key, const float& rate);
Expand Down Expand Up @@ -89,7 +90,7 @@ class PlayerScores
bool IsChartLoaded(const string& ck) { return true; } // obviously not functioning as intended yet


map<string, ScoresForChart> pscores;
unordered_map<string, ScoresForChart> pscores;
map<string, HighScore&> AllScores;
vector<HighScore*> TopSSRs[NUM_Skillset];

Expand Down
8 changes: 8 additions & 0 deletions src/Foreach.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ for( multimap<keyType, valType>::iterator var = (vect).begin(); var != (vect).en
#define FOREACHMM_CONST( keyType, valType, vect, var ) \
for( multimap<keyType, valType>::const_iterator var = (vect).begin(); var != (vect).end(); ++var )

/** @brief General foreach loop iterating over an unordered map. */
#define FOREACHUM( keyType, valType, vect, var ) \
for( unordered_map<keyType, valType>::iterator var = (vect).begin(); var != (vect).end(); ++var )

/** @brief General foreach loop iterating over an unordered map. blah blah const blah*/
#define FOREACHUM_CONST( keyType, valType, vect, var ) \
for( unordered_map<keyType, valType>::const_iterator var = (vect).begin(); var != (vect).end(); ++var )

#endif

/**
Expand Down

0 comments on commit 279150b

Please sign in to comment.