Any suggestions for this implementation? Any changes for this? #pragma once

#include <unordered_map>

#include "Archetype.h"

class ComponentManager
{
private:
    using ComponentTypeIdBaseMap = std::unordered_map<size_t, ComponentBase*>;
public:

    ComponentManager(const ComponentTypeIdBaseMap& componentMap)
        : componentMap_(componentMap)
    {}

    void TransferComponentData(size_t compTypeId,
        Archetype* fromArch,
        Archetype* toArch,
        size_t i,
        size_t j,
        size_t entityIndex);

    void SwapComponentData(size_t compTypeId,
        Archetype* arch,
        size_t toIndex,
        size_t entityIndex);
    
    void RemoveAndAllocateComponentData(size_t compTypeId,
        Archetype* fromArchetype,
        Archetype* toArchetype,
        size_t i,
        size_t j,
        size_t entityIndex);

    size_t FindCurrentSize(size_t compTypeId,
        Archetype* archetype,
        size_t index);

private:

    const ComponentTypeIdBaseMap& componentMap_;

    void Reallocate(size_t compTypeId,
        size_t newComponentDataSize,
        Archetype* archetype,
        size_t index);

    void MoveComponentData(size_t compTypeId,
        Archetype* fromArch,
        Archetype* toArch,
        size_t fromIndex,
        size_t toIndex,
        size_t fromEntityIndex,
        size_t toEntityIndex);

    const ComponentBase* getComponentBase(size_t compTypeId) const {
        auto it = componentMap_.find(compTypeId);
        if (it != componentMap_.end()) {
            return it->second;
        }
        return nullptr;
    }
}; #include "ComponentManager.h"

void ComponentManager::Reallocate(size_t compTypeId, const size_t newComponentDataSize, Archetype* archetype, size_t index) {
    const ComponentBase* componentBase = getComponentBase(compTypeId);
    const std::size_t componentDataSize = componentBase->GetSize();

    archetype->componentDataSize[index] *= 2;
    archetype->componentDataSize[index] += newComponentDataSize;

    unsigned char* newData = new unsigned char[archetype->componentDataSize[index]];

    for (auto e = 0; e < archetype->entityIds.size(); ++e) {
        componentBase->MoveData(&archetype->componentData[index][e * newComponentDataSize],
            &newData[e * newComponentDataSize]);
        componentBase->DestroyData(&archetype->componentData[index][e * newComponentDataSize]);
    }

    delete[] archetype->componentData[index];
    archetype->componentData[index] = newData;
}

void ComponentManager::TransferComponentData(size_t compTypeId, Archetype* fromArch, Archetype* toArch, size_t i, size_t j, size_t entityIndex) {
    MoveComponentData(compTypeId, fromArch, toArch, i, j, entityIndex, toArch->entityIds.size());
}

void ComponentManager::SwapComponentData(size_t compTypeId, Archetype* arch, size_t toIndex, size_t entityIndex) {
    const auto lastEntity = arch->entityIds.size() - 1;

    MoveComponentData(compTypeId, arch, arch, toIndex, toIndex, lastEntity, entityIndex);
}

void ComponentManager::RemoveAndAllocateComponentData(size_t compTypeId, Archetype* fromArchetype, Archetype* toArchetype, size_t i, size_t j, size_t entityIndex) {
    const ComponentBase* componentBase = getComponentBase(compTypeId);
    const std::size_t componentDataSize = componentBase->GetSize();

    size_t currentSize = FindCurrentSize(compTypeId, toArchetype, j);

    const size_t lastEntity = fromArchetype->entityIds.size() - 1;

    componentBase->MoveData(&fromArchetype->componentData[i][entityIndex * componentDataSize],
        &toArchetype->componentData[j][currentSize]);

    if (entityIndex != lastEntity) {
        componentBase->MoveData(&fromArchetype->componentData[i][lastEntity * componentDataSize],
            &fromArchetype->componentData[i][entityIndex * componentDataSize]);
    }

    componentBase->DestroyData(&fromArchetype->componentData[i][lastEntity * componentDataSize]);
}

void ComponentManager::MoveComponentData(size_t compTypeId, Archetype* fromArch, Archetype* toArch, size_t fromIndex, size_t toIndex, size_t fromEntityIndex, size_t toEntityIndex) {
    const ComponentBase* componentBase = getComponentBase(compTypeId);
    const std::size_t componentDataSize = componentBase->GetSize();

    componentBase->MoveData(&fromArch->componentData[fromIndex][fromEntityIndex * componentDataSize],
        &toArch->componentData[toIndex][toEntityIndex * componentDataSize]);
    componentBase->DestroyData(&fromArch->componentData[fromIndex][fromEntityIndex * componentDataSize]);
}

size_t ComponentManager::FindCurrentSize(size_t compTypeId, Archetype* archetype, size_t index) {
    const ComponentBase* compbase = getComponentBase(compTypeId);
    const std::size_t& newCompDataSize = compbase->GetSize();

    std::size_t currentSize = archetype->entityIds.size() * newCompDataSize;
    std::size_t newSize = currentSize + newCompDataSize;

    if (newSize > archetype->componentDataSize[index]) {
        Reallocate(compTypeId, newCompDataSize, archetype, index);
    }

    return currentSize;
}