TSegIdMap indirection fix

This commit is contained in:
Jack Andersen 2016-09-04 08:59:52 -10:00
parent 3ea58fb692
commit 03225d3616
1 changed files with 12 additions and 4 deletions

View File

@ -19,29 +19,37 @@ class TSegIdMap
public: public:
TSegIdMap(const CSegId& capacity) : x1_capacity(capacity), xd0_bones(new T[capacity]) {} TSegIdMap(const CSegId& capacity) : x1_capacity(capacity), xd0_bones(new T[capacity]) {}
T& operator[](const CSegId& id) {return SetElement(id);} T& operator[](const CSegId& id) {return SetElement(id);}
const T& operator[](const CSegId& id) const {return xd0_bones[id];} const T& operator[](const CSegId& id) const {return xd0_bones[x8_indirectionMap[id].second];}
T& SetElement(const CSegId& id, T&& obj) T& SetElement(const CSegId& id, T&& obj)
{ {
xd0_bones[id] = std::move(obj); size_t idx;
if (x8_indirectionMap[id].first == 0xff) if (x8_indirectionMap[id].first == 0xff)
{ {
x8_indirectionMap[id].first = xd4_curPrevBone; x8_indirectionMap[id].first = xd4_curPrevBone;
x8_indirectionMap[id].second = x0_boneCount; x8_indirectionMap[id].second = x0_boneCount;
xd4_curPrevBone = id; xd4_curPrevBone = id;
idx = x0_boneCount;
++x0_boneCount; ++x0_boneCount;
} }
return xd0_bones[id]; else
idx = x8_indirectionMap[id].second;
xd0_bones[idx] = std::move(obj);
return xd0_bones[idx];
} }
T& SetElement(const CSegId& id) T& SetElement(const CSegId& id)
{ {
size_t idx;
if (x8_indirectionMap[id].first == 0xff) if (x8_indirectionMap[id].first == 0xff)
{ {
x8_indirectionMap[id].first = xd4_curPrevBone; x8_indirectionMap[id].first = xd4_curPrevBone;
x8_indirectionMap[id].second = x0_boneCount; x8_indirectionMap[id].second = x0_boneCount;
xd4_curPrevBone = id; xd4_curPrevBone = id;
idx = x0_boneCount;
++x0_boneCount; ++x0_boneCount;
} }
return xd0_bones[id]; else
idx = x8_indirectionMap[id].second;
return xd0_bones[idx];
} }
void DelElement(const CSegId& id) void DelElement(const CSegId& id)
{ {