mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Use std::vector<CNameIndexed> instead of sorted_array
This commit is contained in:
parent
5cc76d286f
commit
ae8f5e87c7
|
@ -112,7 +112,7 @@ void CUuidManager::RegisterName(int ID, const char *pName)
|
|||
CNameIndexed NameIndexed;
|
||||
NameIndexed.m_Uuid = Name.m_Uuid;
|
||||
NameIndexed.m_ID = GetIndex(ID);
|
||||
m_aNamesSorted.add(NameIndexed);
|
||||
m_aNamesSorted.insert(std::lower_bound(m_aNamesSorted.begin(), m_aNamesSorted.end(), NameIndexed), NameIndexed);
|
||||
}
|
||||
|
||||
CUuid CUuidManager::GetUuid(int ID) const
|
||||
|
@ -127,10 +127,13 @@ const char *CUuidManager::GetName(int ID) const
|
|||
|
||||
int CUuidManager::LookupUuid(CUuid Uuid) const
|
||||
{
|
||||
sorted_array<CNameIndexed>::range Pos = ::find_binary(m_aNamesSorted.all(), Uuid);
|
||||
if(!Pos.empty())
|
||||
CNameIndexed Needle;
|
||||
Needle.m_Uuid = Uuid;
|
||||
Needle.m_ID = 0;
|
||||
auto Range = std::equal_range(m_aNamesSorted.begin(), m_aNamesSorted.end(), Needle);
|
||||
if(std::distance(Range.first, Range.second) == 1)
|
||||
{
|
||||
return GetID(Pos.front().m_ID);
|
||||
return GetID(Range.first->m_ID);
|
||||
}
|
||||
return UUID_UNKNOWN;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define ENGINE_SHARED_UUID_MANAGER_H
|
||||
|
||||
#include <base/tl/array.h>
|
||||
#include <base/tl/sorted_array.h>
|
||||
#include <vector>
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -42,8 +42,7 @@ struct CNameIndexed
|
|||
int m_ID;
|
||||
|
||||
bool operator<(const CNameIndexed &Other) const { return m_Uuid < Other.m_Uuid; }
|
||||
bool operator<(const CUuid &Other) const { return m_Uuid < Other; }
|
||||
bool operator==(const CUuid &Other) const { return m_Uuid == Other; }
|
||||
bool operator==(const CNameIndexed &Other) const { return m_Uuid == Other.m_Uuid; }
|
||||
};
|
||||
|
||||
class CPacker;
|
||||
|
@ -52,7 +51,7 @@ class CUnpacker;
|
|||
class CUuidManager
|
||||
{
|
||||
array<CName> m_aNames;
|
||||
sorted_array<CNameIndexed> m_aNamesSorted;
|
||||
std::vector<CNameIndexed> m_aNamesSorted;
|
||||
|
||||
public:
|
||||
void RegisterName(int ID, const char *pName);
|
||||
|
|
Loading…
Reference in a new issue