refactor(lfg): refactor code and style (#3326)

* Update AuctionHouseHandler.cpp

* refactor(LFG): improve code style

* refactor(LFG): minor improvements

* chore(LFG): improve code style

* refactor(lfg): improve code style

Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com>
Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
Stefano Borzì
2020-09-04 10:18:43 +02:00
committed by GitHub
parent 8f6c22afda
commit e9c805a743

View File

@@ -104,85 +104,369 @@ class Lfg5Guids
public:
uint64 guid[5];
LfgRolesMap* roles;
Lfg5Guids() { memset(&guid, 0, 5*8); roles = nullptr; }
Lfg5Guids(uint64 g) { memset(&guid, 0, 5*8); guid[0] = g; roles = nullptr; }
Lfg5Guids(Lfg5Guids const& x) { memcpy(guid, x.guid, 5*8); if (x.roles) roles = new LfgRolesMap(*(x.roles)); else roles = nullptr; }
Lfg5Guids(Lfg5Guids const& x, bool /*copyRoles*/) { memcpy(guid, x.guid, 5*8); roles = nullptr; }
Lfg5Guids()
{
memset(&guid, 0, 5*8);
roles = nullptr;
}
Lfg5Guids(uint64 g)
{
memset(&guid, 0, 5*8);
guid[0] = g;
roles = nullptr;
}
Lfg5Guids(Lfg5Guids const& x)
{
memcpy(guid, x.guid, 5*8);
roles = x.roles ? (new LfgRolesMap(*(x.roles))) : nullptr;
}
Lfg5Guids(Lfg5Guids const& x, bool /*copyRoles*/)
{
memcpy(guid, x.guid, 5*8);
roles = nullptr;
}
~Lfg5Guids() { delete roles; }
void addRoles(LfgRolesMap const& r) { roles = new LfgRolesMap(r); }
void clear() { memset(&guid, 0, 5*8); }
bool empty() const { return guid[0] == 0; }
uint64 front() const { return guid[0]; }
uint8 size() const
{
if (guid[2])
{
if (guid[4]) return 5;
else if (guid[3]) return 4;
if (guid[4])
{
return 5;
}
else if (guid[3])
{
return 4;
}
return 3;
}
else if (guid[1]) return 2;
else if (guid[0]) return 1;
else if (guid[1])
{
return 2;
}
else if (guid[0])
{
return 1;
}
return 0;
}
void insert(const uint64& g)
{
// avoid loops for performance
if (guid[0] == 0) { guid[0] = g; return; }
else if (g <= guid[0]) { if (guid[3]) guid[4] = guid[3]; if (guid[2]) guid[3] = guid[2]; if (guid[1]) guid[2] = guid[1]; guid[1] = guid[0]; guid[0] = g; return; }
if (guid[1] == 0) { guid[1] = g; return; }
else if (g <= guid[1]) { if (guid[3]) guid[4] = guid[3]; if (guid[2]) guid[3] = guid[2]; guid[2] = guid[1]; guid[1] = g; return; }
if (guid[2] == 0) { guid[2] = g; return; }
else if (g <= guid[2]) { if (guid[3]) guid[4] = guid[3]; guid[3] = guid[2]; guid[2] = g; return; }
if (guid[3] == 0) { guid[3] = g; return; }
else if (g <= guid[3]) { guid[4] = guid[3]; guid[3] = g; return; }
if (guid[0] == 0)
{
guid[0] = g;
return;
}
if (g <= guid[0])
{
if (guid[3])
{
guid[4] = guid[3];
}
if (guid[2])
{
guid[3] = guid[2];
}
if (guid[1])
{
guid[2] = guid[1];
}
guid[1] = guid[0];
guid[0] = g;
return;
}
if (guid[1] == 0)
{
guid[1] = g;
return;
}
if (g <= guid[1])
{
if (guid[3])
{
guid[4] = guid[3];
}
if (guid[2])
{
guid[3] = guid[2];
}
guid[2] = guid[1];
guid[1] = g;
return;
}
if (guid[2] == 0)
{
guid[2] = g;
return;
}
if (g <= guid[2])
{
if (guid[3])
{
guid[4] = guid[3];
}
guid[3] = guid[2];
guid[2] = g;
return;
}
if (guid[3] == 0)
{
guid[3] = g;
return;
}
if (g <= guid[3])
{
guid[4] = guid[3];
guid[3] = g;
return;
}
guid[4] = g;
}
void force_insert_front(const uint64& g)
{
if (guid[3]) guid[4] = guid[3]; if (guid[2]) guid[3] = guid[2]; if (guid[1]) guid[2] = guid[1]; guid[1] = guid[0]; guid[0] = g;
if (guid[3])
{
guid[4] = guid[3];
}
if (guid[2])
{
guid[3] = guid[2];
}
if (guid[1])
{
guid[2] = guid[1];
}
guid[1] = guid[0];
guid[0] = g;
}
void remove(const uint64& g)
{
// avoid loops for performance
if (guid[0] == g) { if (guid[1]) guid[0] = guid[1]; else { guid[0] = 0; return; } if (guid[2]) guid[1] = guid[2]; else { guid[1] = 0; return; } if (guid[3]) guid[2] = guid[3]; else { guid[2] = 0; return; } if (guid[4]) guid[3] = guid[4]; else { guid[3] = 0; return; } guid[4] = 0; return; }
if (guid[1] == g) { if (guid[2]) guid[1] = guid[2]; else { guid[1] = 0; return; } if (guid[3]) guid[2] = guid[3]; else { guid[2] = 0; return; } if (guid[4]) guid[3] = guid[4]; else { guid[3] = 0; return; } guid[4] = 0; return; }
if (guid[2] == g) { if (guid[3]) guid[2] = guid[3]; else { guid[2] = 0; return; } if (guid[4]) guid[3] = guid[4]; else { guid[3] = 0; return; } guid[4] = 0; return; }
if (guid[3] == g) { if (guid[4]) guid[3] = guid[4]; else { guid[3] = 0; return; } guid[4] = 0; return; }
if (guid[4] == g) guid[4] = 0;
if (guid[0] == g)
{
if (guid[1])
{
guid[0] = guid[1];
}
else
{
guid[0] = 0;
return;
}
if (guid[2])
{
guid[1] = guid[2];
}
else
{
guid[1] = 0;
return;
}
if (guid[3])
{
guid[2] = guid[3];
}
else
{
guid[2] = 0;
return;
}
if (guid[4])
{
guid[3] = guid[4];
}
else
{
guid[3] = 0;
return;
}
guid[4] = 0;
return;
}
if (guid[1] == g)
{
if (guid[2])
{
guid[1] = guid[2];
}
else
{
guid[1] = 0;
return;
}
if (guid[3])
{
guid[2] = guid[3];
}
else
{
guid[2] = 0;
return;
}
if (guid[4])
{
guid[3] = guid[4];
}
else
{
guid[3] = 0;
return;
}
guid[4] = 0;
return;
}
if (guid[2] == g)
{
if (guid[3])
{
guid[2] = guid[3];
}
else
{
guid[2] = 0;
return;
}
if (guid[4])
{
guid[3] = guid[4];
}
else
{
guid[3] = 0;
return;
}
guid[4] = 0;
return;
}
if (guid[3] == g)
{
if (guid[4])
{
guid[3] = guid[4];
}
else
{
guid[3] = 0;
return;
}
guid[4] = 0;
return;
}
if (guid[4] == g)
{
guid[4] = 0;
}
}
bool hasGuid(const uint64& g) const
{
return g && (guid[0] == g || guid[1] == g || guid[2] == g || guid[3] == g || guid[4] == g);
}
bool operator<(const Lfg5Guids& x) const
{
// not neat, but fast xD
if (guid[0]<=x.guid[0]) {
if (guid[0] == x.guid[0]) {
if (guid[1]<=x.guid[1]) {
if (guid[1] == x.guid[1]) {
if (guid[2]<=x.guid[2]) {
if (guid[2] == x.guid[2]) {
if (guid[3]<=x.guid[3]) {
if (guid[3] == x.guid[3]) {
if (guid[4]<=x.guid[4]) {
if (guid[4] == x.guid[4]) return false; else return true;
} else return false;
} else return true;
} else return false;
} else return true;
} else return false;
} else return true;
} else return false;
} else return true;
} else return false;
if (guid[0] <= x.guid[0])
{
if (guid[0] != x.guid[0])
{
return true;
}
if (guid[1] <= x.guid[1])
{
if (guid[1] != x.guid[1])
{
return true;
}
if (guid[2] <= x.guid[2])
{
if (guid[2] != x.guid[2])
{
return true;
}
if (guid[3] <= x.guid[3])
{
if (guid[3] != x.guid[3])
{
return true;
}
if (guid[4] <= x.guid[4])
{
return !(guid[4] == x.guid[4]);
}
}
}
}
}
return false;
}
bool operator==(const Lfg5Guids& x) const
{
return guid[0] == x.guid[0] && guid[1] == x.guid[1] && guid[2] == x.guid[2] && guid[3] == x.guid[3] && guid[4] == x.guid[4];
}
void operator=(const Lfg5Guids& x) { memcpy(guid, x.guid, 5*8); delete roles; if (x.roles) roles = new LfgRolesMap(*(x.roles)); else roles = nullptr; }
void operator=(const Lfg5Guids& x)
{
memcpy(guid, x.guid, 5*8);
delete roles;
roles = x.roles ? (new LfgRolesMap(*(x.roles))) : nullptr;
}
std::string toString() const // for debugging
{
std::ostringstream o;