Use std::vector<CNameIndexed> instead of sorted_array

This commit is contained in:
Robert Müller 2022-05-23 22:01:12 +02:00 committed by heinrich5991
parent 5cc76d286f
commit ae8f5e87c7
2 changed files with 10 additions and 8 deletions

View file

@ -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;
}

View file

@ -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);