diff --git a/PolyEngine/Core/Src/pe/Defines.hpp b/PolyEngine/Core/Src/pe/Defines.hpp index 8efd1314..8ffcceed 100755 --- a/PolyEngine/Core/Src/pe/Defines.hpp +++ b/PolyEngine/Core/Src/pe/Defines.hpp @@ -85,6 +85,7 @@ #include #include #include +#include #include #include diff --git a/PolyEngine/Core/Src/pe/core/storage/PriorityQueue.hpp b/PolyEngine/Core/Src/pe/core/storage/PriorityQueue.hpp index 7bc05d50..e657ca50 100644 --- a/PolyEngine/Core/Src/pe/core/storage/PriorityQueue.hpp +++ b/PolyEngine/Core/Src/pe/core/storage/PriorityQueue.hpp @@ -2,109 +2,82 @@ #include - namespace pe::core::storage { - template - struct DefaultCmp - { - bool operator()(const T& a, const T& b) const { return a < b; } - }; - - - template > - class PriorityQueue final : BaseObjectLiteralType<> + template::value_type> > + class PriorityQueue final : public std::priority_queue,Pr> { public: - PriorityQueue(size_t prealocatedSize = 0) { Data.reserve(prealocatedSize); } - PriorityQueue(Less lessCmp, size_t prealocatedSize = 0) : LessCmp(std::move(lessCmp)) { Data.reserve(prealocatedSize);} - PriorityQueue(std::vector data) : Data(std::move(data)) + + PriorityQueue() + : std::priority_queue, Pr>() { - for (size_t idx = Data.size() / 2; idx > 0; --idx) - SiftDown(idx - 1); } - void Push(T val) - { - Data.push_back(std::move(val)); - SiftUp(Data.size() - 1); + PriorityQueue(const std::vector& _Cont) + : std::priority_queue, Pr>(Pr(), _Cont) + { } - T Pop() - { - T& first = Data[0]; - T& last = Data[GetSize() - 1]; - T tmp = std::move(first); - Swap(first, last); - Data.pop_back(); - SiftDown(0); - return tmp; + PriorityQueue(const Pr& Pred, const std::vector& _Cont) + : std::priority_queue, Pr>(Pred,_Cont) + { } - void Clear() { Data.clear(); } - const T& Head() const { return Data[0]; } - size_t GetSize() const { return Data.size(); } - void Reserve(size_t size) { Data.reserve(size); } - private: - void SiftUp(size_t idx) + explicit PriorityQueue(const Pr& Pred) + : std::priority_queue, Pr>(Pred) { - while (idx > 0) - { - T& val = Data[idx]; - const size_t parentIdx = GetParent(idx); - T& parent = Data[parentIdx]; - if (!LessCmp(val, parent)) - break; - - Swap(val, parent); - idx = parentIdx; - } } - void SiftDown(size_t idx) - { - while (idx < GetSize()) - { - const size_t leftChild = GetLeftChild(idx); - const size_t rightChild = GetRightChild(idx); - - const bool leftOk = leftChild < GetSize(); - const bool rightOk = rightChild < GetSize(); - - if (!leftOk && !rightOk) - return; - - T& val = Data[idx]; - // assign val, simple trick to bypass null reference limitations - T* left = leftOk ? &Data[leftChild] : nullptr; - T* right = rightOk ? &Data[rightChild] : nullptr; - - const bool rightBetter = !leftOk || (rightOk && LessCmp(*right, *left)); - T* candidate = rightBetter ? right : left; - - if (candidate && LessCmp(*candidate, val)) - { - Swap(val, *candidate); - idx = rightBetter ? rightChild : leftChild; - } - else - return; - } + + template + PriorityQueue(InIt _First, InIt _Last) + : std::priority_queue, Pr>(_First,_Last) + { } - inline void Swap(T& a, T& b) - { - T tmp = std::move(a); - a = std::move(b); - b = std::move(tmp); + template + PriorityQueue(InIt _First, InIt _Last, const Pr& Pred) + : std::priority_queue, Pr>(_First,_Last,Pred) + { } - inline size_t GetParent(size_t node) { return (node - 1) / 2; } - inline size_t GetLeftChild(size_t node) { return 2 * node + 1; } - inline size_t GetRightChild(size_t node) { return 2 * node + 2; } + + template, Alloc>>> + explicit PriorityQueue(const Alloc& _Al) + : std::priority_queue, Pr>(_Al) + { + } - Less LessCmp; - std::vector Data; + template, Alloc>>> + PriorityQueue(const Pr& Pred, const Alloc& _Al) + : std::priority_queue, Pr>(Pred,_Al) + { + } + + template, Alloc>>> + PriorityQueue(const std::priority_queue, Pr>& _Right, const Alloc& _Al) + : std::priority_queue, Pr>(_Right,_Al) + { + } + + + template, Alloc>>> + PriorityQueue(std::priority_queue, Pr>&& _Right, const Alloc& _Al) + : std::priority_queue, Pr>(_Right,_Al) + { + } + + + void clear() + { + this->c.clear(); + } }; -} //namespace Poly +} + diff --git a/PolyEngine/Core/Src/pe/core/storage/impl/IndexedStringManager.cpp b/PolyEngine/Core/Src/pe/core/storage/impl/IndexedStringManager.cpp index c19077b0..b49763bb 100644 --- a/PolyEngine/Core/Src/pe/core/storage/impl/IndexedStringManager.cpp +++ b/PolyEngine/Core/Src/pe/core/storage/impl/IndexedStringManager.cpp @@ -56,7 +56,7 @@ void IndexedStringManager::scheduleErase(const IndexedStringEntry* entry) HEAVY_ASSERTE(entry->getRemovalTimePoint().value_or(0) <= removalTimePoint, "Cannot set removal time point to a previous one than already set!"); entry->setRemovalTimePoint(removalTimePoint); - m_ttlEntries.Push(TTLEntry{removalTimePoint, entry}); + m_ttlEntries.emplace(TTLEntry{removalTimePoint, entry}); } void IndexedStringManager::erase(const IndexedStringEntry* entry) @@ -70,7 +70,7 @@ void IndexedStringManager::setTTLMode(bool enabled) { if(m_ttlEnabled && !enabled) { - m_ttlEntries.Clear(); + m_ttlEntries.clear(); } m_ttlEnabled = enabled; } @@ -88,9 +88,10 @@ void IndexedStringManager::tickTTL(size_t ttlTickCount) m_tickCount += ttlTickCount; - while(m_ttlEntries.GetSize() > 0 && m_ttlEntries.Head().m_scheduledTimePoint <= m_tickCount) + while(m_ttlEntries.size() > 0 && m_ttlEntries.top().m_scheduledTimePoint <= m_tickCount) { - auto entry = m_ttlEntries.Pop().m_entry; + auto entry = m_ttlEntries.top().m_entry; + m_ttlEntries.pop(); auto realRemovalTimePoint = entry->getRemovalTimePoint(); if (realRemovalTimePoint.value_or(m_tickCount+1) <= m_tickCount) { diff --git a/PolyEngine/Core/Src/pe/core/storage/impl/IndexedStringManager.hpp b/PolyEngine/Core/Src/pe/core/storage/impl/IndexedStringManager.hpp index 25bf703a..7aa02149 100644 --- a/PolyEngine/Core/Src/pe/core/storage/impl/IndexedStringManager.hpp +++ b/PolyEngine/Core/Src/pe/core/storage/impl/IndexedStringManager.hpp @@ -13,6 +13,7 @@ struct TTLEntry const IndexedStringEntry* m_entry; bool operator<(const TTLEntry& rhs) const { return m_scheduledTimePoint < rhs.m_scheduledTimePoint; } + bool operator>(const TTLEntry& rhs) const { return m_scheduledTimePoint > rhs.m_scheduledTimePoint; } }; class CORE_DLLEXPORT IndexedStringManager final : public core::BaseObjectLiteralType<> diff --git a/PolyEngine/Engine/Src/AI/PathfindingSystem.cpp b/PolyEngine/Engine/Src/AI/PathfindingSystem.cpp index 0c152ff8..ad7e1fd1 100644 --- a/PolyEngine/Engine/Src/AI/PathfindingSystem.cpp +++ b/PolyEngine/Engine/Src/AI/PathfindingSystem.cpp @@ -40,15 +40,16 @@ std::optional> CalculateNewPath(const NavG std::map minCosts; AllNodes.push_back(PathNode(startNode, 0, graph->GetHeuristicCost(startNode, destNode) )); - openList.Push(std::make_pair(AllNodes.size() - 1, graph->GetHeuristicCost(startNode, destNode))); + openList.emplace(AllNodes.size() - 1, graph->GetHeuristicCost(startNode, destNode)); minCosts.emplace(startNode, 0.f); i64 bestNodeIdx = -1; std::vector connections(8); - while (openList.GetSize() > 0 && bestNodeIdx < 0) + while (openList.size() > 0 && bestNodeIdx < 0) { - i64 qIdx = openList.Pop().first; - + i64 qIdx = openList.top().first; + openList.pop(); + connections.clear(); graph->GetConnections(AllNodes[qIdx].Node, connections); for (const NavNode* connection : connections) @@ -70,11 +71,11 @@ std::optional> CalculateNewPath(const NavG continue; // node has worse base cost than other (in the same pos) we visited before, skip it AllNodes.push_back(s); - openList.Push(std::make_pair(AllNodes.size() - 1, s.TotalCost())); + openList.emplace(AllNodes.size() - 1, s.TotalCost()); minCosts[s.Node] = s.Cost; } - closedList.Push(std::make_pair(qIdx, AllNodes[qIdx].TotalCost())); + closedList.emplace(qIdx, AllNodes[qIdx].TotalCost()); minCosts[AllNodes[qIdx].Node] = AllNodes[qIdx].Cost; } diff --git a/PolyEngine/Engine/Src/EnginePCH.hpp b/PolyEngine/Engine/Src/EnginePCH.hpp index 7a57b267..9c9e7bfb 100644 --- a/PolyEngine/Engine/Src/EnginePCH.hpp +++ b/PolyEngine/Engine/Src/EnginePCH.hpp @@ -43,6 +43,7 @@ #include #include + // Other #include #include diff --git a/PolyEngine/Engine/Src/Resources/MeshResource.cpp b/PolyEngine/Engine/Src/Resources/MeshResource.cpp index bf11e6ea..fa03c42f 100644 --- a/PolyEngine/Engine/Src/Resources/MeshResource.cpp +++ b/PolyEngine/Engine/Src/Resources/MeshResource.cpp @@ -6,6 +6,8 @@ using namespace Poly; +using PairQueue = core::storage::PriorityQueue,std::function&, const std::pair&)>>; + RTTI_DEFINE_TYPE(Poly::MeshResource) core::math::Matrix MatFromAiMat(const aiMatrix4x4& m) @@ -150,9 +152,9 @@ void MeshResource::SubMesh::LoadBones(aiMesh* mesh) if (mesh->HasBones()) { ASSERTE((i8)mesh->mNumBones <= std::numeric_limits::max(), "Model has too many bones!"); - - std::vector<::pe::core::storage::PriorityQueue, std::function&, const std::pair&)>>> tmpBonesList; - tmpBonesList.resize(mesh->mNumVertices, { [](const std::pair& v1, const std::pair& v2) { return v1.second > v2.second; } }); + + std::vector tmpBonesList; + tmpBonesList.resize(mesh->mNumVertices, { PairQueue([](const std::pair& v1, const std::pair& v2) { return v1.second > v2.second; })}); std::map<::pe::core::storage::String, size_t> nameToBoneIdx; @@ -169,7 +171,7 @@ void MeshResource::SubMesh::LoadBones(aiMesh* mesh) const auto& vertWeight = bone->mWeights[j]; size_t vertId = vertWeight.mVertexId; float weight = vertWeight.mWeight; - tmpBonesList[vertId].Push({ boneId, weight }); + tmpBonesList[vertId].emplace( boneId, weight ); } } } @@ -182,11 +184,12 @@ void MeshResource::SubMesh::LoadBones(aiMesh* mesh) for (size_t vertId = 0; vertId < mesh->mNumVertices; ++vertId) { - auto& boneQueue = tmpBonesList[vertId]; + PairQueue& boneQueue = tmpBonesList[vertId]; float sum = 0.f; - for (size_t k = 0; k < 4 && boneQueue.GetSize() > 0; ++k) + for (size_t k = 0; k < 4 && boneQueue.size() > 0; ++k) { - auto entry = boneQueue.Pop(); + auto entry = boneQueue.top(); + boneQueue.pop(); sum += entry.second; MeshData.BoneIds[vertId].Data[k] = entry.first; MeshData.BoneWeights[vertId].Data[k] = entry.second; diff --git a/PolyEngine/RenderingDevice/OpenGL/Src/GLWorldRendering.cpp b/PolyEngine/RenderingDevice/OpenGL/Src/GLWorldRendering.cpp index 5bf88de9..c8921040 100644 --- a/PolyEngine/RenderingDevice/OpenGL/Src/GLWorldRendering.cpp +++ b/PolyEngine/RenderingDevice/OpenGL/Src/GLWorldRendering.cpp @@ -3,7 +3,7 @@ #include #include // std::min - +#include #include #include #include @@ -82,18 +82,18 @@ void GLRenderingDevice::FillSceneView(SceneView& sceneView) { if (meshCmp->GetBlendingMode() == eBlendingMode::OPAUQE) { - sceneView.OpaqueQueue.Push(meshCmp); + sceneView.OpaqueQueue.push(meshCmp); } else if (meshCmp->GetBlendingMode() == eBlendingMode::TRANSLUCENT) { - sceneView.TranslucentQueue.Push(meshCmp); + sceneView.TranslucentQueue.push(meshCmp); } } } for (const auto& [particleCmp] : sceneView.SceneData->IterateComponents()) { - sceneView.ParticleQueue.Push(particleCmp); + sceneView.ParticleQueue.push(particleCmp); } for (const auto& [dirLightCmp] : sceneView.SceneData->IterateComponents()) @@ -237,13 +237,12 @@ void GLRenderingDevice::CullShadowCasters(SceneView& sceneView, const core::math // find all meshes that are inside extended DirLights AABB box core::math::Vector dirLightPos = sceneView.DirectionalLightList[0]->GetTransform().GetGlobalTranslation(); - MeshQueue shadowCasterQueue(SceneView::DistanceToCameraComparator(dirLightPos, SceneView::eSortOrderType::FRONT_TO_BACK), 0); - + MeshQueue shadowCasterQueue(SceneView::DistanceToCameraComparator(dirLightPos, SceneView::eSortOrderType::FRONT_TO_BACK)); for (auto& [box, meshCmp] : boxMeshes) { if (frustumAABBInLS.Contains(box)) { - shadowCasterQueue.Push(meshCmp); + shadowCasterQueue.push(meshCmp); if (sceneView.SettingsCmp && sceneView.SettingsCmp->DebugDrawShadowCastersBounds) DebugDrawSystem::DrawBox(scene, box.GetMin(), box.GetMax(), worldFromDirLight, core::math::Color::GREEN); diff --git a/PolyEngine/RenderingDevice/OpenGL/Src/IRendererInterface.hpp b/PolyEngine/RenderingDevice/OpenGL/Src/IRendererInterface.hpp index ba821403..7a189b5e 100644 --- a/PolyEngine/RenderingDevice/OpenGL/Src/IRendererInterface.hpp +++ b/PolyEngine/RenderingDevice/OpenGL/Src/IRendererInterface.hpp @@ -4,6 +4,7 @@ #include #include #include +#include // TODO: inherit from BaseRenderPass - make multipass RenderPass @@ -54,10 +55,10 @@ namespace Poly { SceneView(Scene* s, Viewport& v) : SceneData(s), ViewportData(v), Rect(v.GetRect()), CameraCmp(v.GetCamera()), - DirShadowCastersQueue(DistanceToCameraComparator(::pe::core::math::Vector::ZERO, eSortOrderType::FRONT_TO_BACK), 0), // filled by GLRenderingDevice::CullShadowCasters - OpaqueQueue(DistanceToCameraComparator(v.GetCamera()->GetTransform().GetGlobalTranslation(), eSortOrderType::FRONT_TO_BACK), 0), - TranslucentQueue(DistanceToCameraComparator(v.GetCamera()->GetTransform().GetGlobalTranslation(), eSortOrderType::BACK_TO_FRONT), 0), - ParticleQueue(DistanceToCameraComparator(v.GetCamera()->GetTransform().GetGlobalTranslation(), eSortOrderType::BACK_TO_FRONT), 0) + DirShadowCastersQueue(DistanceToCameraComparator(::pe::core::math::Vector::ZERO, eSortOrderType::FRONT_TO_BACK)), // filled by GLRenderingDevice::CullShadowCasters + OpaqueQueue(DistanceToCameraComparator(v.GetCamera()->GetTransform().GetGlobalTranslation(), eSortOrderType::FRONT_TO_BACK)), + TranslucentQueue(DistanceToCameraComparator(v.GetCamera()->GetTransform().GetGlobalTranslation(), eSortOrderType::BACK_TO_FRONT)), + ParticleQueue(DistanceToCameraComparator(v.GetCamera()->GetTransform().GetGlobalTranslation(), eSortOrderType::BACK_TO_FRONT)) { SettingsCmp = s->GetWorldComponent(); }; @@ -69,10 +70,10 @@ namespace Poly { const CameraComponent* CameraCmp; const RenderingSettingsComponent* SettingsCmp; - ::pe::core::storage::PriorityQueue DirShadowCastersQueue; - ::pe::core::storage::PriorityQueue OpaqueQueue; - ::pe::core::storage::PriorityQueue TranslucentQueue; - ::pe::core::storage::PriorityQueue ParticleQueue; // TODO: make translucent and particles one queue with common priority + core::storage::PriorityQueue DirShadowCastersQueue; + core::storage::PriorityQueue OpaqueQueue; + core::storage::PriorityQueue TranslucentQueue; + core::storage::PriorityQueue ParticleQueue; // TODO: make translucent and particles one queue with common priority ::pe::core::math::AABox DirShadowAABBInLS; std::vector DirectionalLightList; diff --git a/PolyEngine/RenderingDevice/OpenGL/Src/Pipeline/ShadowMapPass.cpp b/PolyEngine/RenderingDevice/OpenGL/Src/Pipeline/ShadowMapPass.cpp index 9fe46516..2131368f 100644 --- a/PolyEngine/RenderingDevice/OpenGL/Src/Pipeline/ShadowMapPass.cpp +++ b/PolyEngine/RenderingDevice/OpenGL/Src/Pipeline/ShadowMapPass.cpp @@ -1,5 +1,5 @@ #include - +#include #include #include #include @@ -228,9 +228,10 @@ void ShadowMapPass::RenderPCF(const SceneView& sceneView) ShadowMapShader.BindProgram(); MeshQueue dirShadowCasterQueue(sceneView.DirShadowCastersQueue); - while (dirShadowCasterQueue.GetSize() > 0) + while (dirShadowCasterQueue.size() > 0) { - const MeshRenderingComponent* meshCmp = dirShadowCasterQueue.Pop(); + const MeshRenderingComponent* meshCmp = dirShadowCasterQueue.top(); + dirShadowCasterQueue.pop(); const core::math::Matrix& worldFromModel = meshCmp->GetTransform().GetWorldFromModel(); ShadowMapShader.SetUniform("uClipFromModel", orthoDirLightFromWorld * worldFromModel); @@ -264,9 +265,10 @@ void ShadowMapPass::RenderEVSM(const SceneView& sceneView) ShadowMapShader.BindProgram(); MeshQueue dirShadowCasterQueue(sceneView.DirShadowCastersQueue); - while (dirShadowCasterQueue.GetSize() > 0) + while (dirShadowCasterQueue.size() > 0) { - const MeshRenderingComponent* meshCmp = dirShadowCasterQueue.Pop(); + const MeshRenderingComponent* meshCmp = dirShadowCasterQueue.top(); + dirShadowCasterQueue.pop(); const core::math::Matrix& worldFromModel = meshCmp->GetTransform().GetWorldFromModel(); ShadowMapShader.SetUniform("uClipFromModel", orthoDirLightFromWorld * worldFromModel); diff --git a/PolyEngine/RenderingDevice/OpenGL/Src/PolyRenderingDeviceGLPCH.hpp b/PolyEngine/RenderingDevice/OpenGL/Src/PolyRenderingDeviceGLPCH.hpp index 88c06962..bace0d74 100644 --- a/PolyEngine/RenderingDevice/OpenGL/Src/PolyRenderingDeviceGLPCH.hpp +++ b/PolyEngine/RenderingDevice/OpenGL/Src/PolyRenderingDeviceGLPCH.hpp @@ -34,7 +34,7 @@ #include #include -#include + // Other #include diff --git a/PolyEngine/RenderingDevice/OpenGL/Src/TiledForwardRenderer.cpp b/PolyEngine/RenderingDevice/OpenGL/Src/TiledForwardRenderer.cpp index 0be1bc0e..918dcfc2 100644 --- a/PolyEngine/RenderingDevice/OpenGL/Src/TiledForwardRenderer.cpp +++ b/PolyEngine/RenderingDevice/OpenGL/Src/TiledForwardRenderer.cpp @@ -3,7 +3,7 @@ #include #include #include - +#include #include #include #include @@ -525,9 +525,10 @@ void TiledForwardRenderer::RenderDepthPrePass(const SceneView& sceneView) const core::math::Matrix& clipFromWorld = sceneView.CameraCmp->GetClipFromWorld(); MeshQueue drawOpaqueQueue(sceneView.OpaqueQueue); - while(drawOpaqueQueue.GetSize() > 0) + while(drawOpaqueQueue.size() > 0) { - const MeshRenderingComponent* meshCmp = drawOpaqueQueue.Pop(); + const MeshRenderingComponent* meshCmp = drawOpaqueQueue.top(); + drawOpaqueQueue.pop(); const core::math::Matrix& worldFromModel = meshCmp->GetTransform().GetWorldFromModel(); static const core::storage::String uScreenFromModel("uScreenFromModel"); DepthShader.SetUniform(uScreenFromModel, clipFromWorld * worldFromModel); @@ -691,9 +692,10 @@ void TiledForwardRenderer::RenderOpaqueLit(const SceneView& sceneView) const core::math::Matrix& clipFromWorld = sceneView.CameraCmp->GetClipFromWorld(); core::storage::PriorityQueue drawOpaqueQueue(sceneView.OpaqueQueue); - while (drawOpaqueQueue.GetSize() > 0) + while (drawOpaqueQueue.size() > 0) { - const MeshRenderingComponent* meshCmp = drawOpaqueQueue.Pop(); + const MeshRenderingComponent* meshCmp = drawOpaqueQueue.top(); + drawOpaqueQueue.pop(); const SkeletalAnimationComponent* animCmp = meshCmp->GetSibling(); const EntityTransform& transform = meshCmp->GetTransform(); @@ -902,9 +904,10 @@ void TiledForwardRenderer::RenderTranslucentLit(const SceneView& sceneView) // for (const MeshRenderingComponent* meshCmp : sceneView.TranslucentQueue) // { core::storage::PriorityQueue drawTranslucentQueue(sceneView.TranslucentQueue); - while (drawTranslucentQueue.GetSize() > 0) + while (drawTranslucentQueue.size() > 0) { - const MeshRenderingComponent* meshCmp = drawTranslucentQueue.Pop(); + const MeshRenderingComponent* meshCmp = drawTranslucentQueue.top(); + drawTranslucentQueue.pop(); const EntityTransform& transform = meshCmp->GetTransform(); const core::math::Matrix& worldFromModel = transform.GetWorldFromModel(); static const core::storage::String uClipFromModel("uClipFromModel"); diff --git a/PolyEngine/Tests/CoreTests/Src/PriorityQueueTests.cpp b/PolyEngine/Tests/CoreTests/Src/PriorityQueueTests.cpp index e295f5b7..616ac468 100644 --- a/PolyEngine/Tests/CoreTests/Src/PriorityQueueTests.cpp +++ b/PolyEngine/Tests/CoreTests/Src/PriorityQueueTests.cpp @@ -9,32 +9,32 @@ TEST_CASE("PriorityQueue sorted push test", "[PriorityQueue]") for (int i = 0; i < testSize; ++i) { - q.Push(i); - CHECK(q.GetSize() == i+1); + q.push(i); + CHECK(q.size() == i+1); } for (int i = 0; i < testSize; ++i) { - CHECK(q.Head() == i); - CHECK(q.Pop() == i); + CHECK(q.top() == i); + q.pop(); } } -TEST_CASE("PriorityQueue reverrse sorted push test", "[PriorityQueue]") +TEST_CASE("PriorityQueue reverse sorted push test", "[PriorityQueue]") { ::pe::core::storage::PriorityQueue q; const int testSize = 100; for (int i = 0; i < testSize; ++i) { - q.Push(testSize - i - 1); - CHECK(q.GetSize() == i + 1); + q.push(testSize - i - 1); + CHECK(q.size() == i + 1); } for (int i = 0; i < testSize; ++i) { - CHECK(q.Head() == i); - CHECK(q.Pop() == i); + CHECK(q.top() == i); + q.pop(); } } @@ -45,20 +45,21 @@ TEST_CASE("PriorityQueue random push test", "[PriorityQueue]") for (size_t i = 0; i < testSize; ++i) { - q.Push(rand()); - CHECK(q.GetSize() == i + 1); + q.push(rand()); + CHECK(q.size() == i + 1); } for (size_t i = 0; i < testSize - 1; ++i) { - size_t v1 = q.Pop(); - CHECK(v1 <= q.Head()); + size_t v1 = q.top(); + q.pop(); + CHECK(v1 <= q.top()); } } struct CustomTestComparator { - bool operator()(int a, int b) const { return a > b; } + bool operator()(int a, int b) const { return a < b; } }; TEST_CASE("PriorityQueue custom comparator test", "[PriorityQueue]") @@ -68,14 +69,15 @@ TEST_CASE("PriorityQueue custom comparator test", "[PriorityQueue]") for (size_t i = 0; i < testSize; ++i) { - q.Push(rand()); - CHECK(q.GetSize() == i + 1); + q.push(rand()); + CHECK(q.size() == i + 1); } for (size_t i = 0; i < testSize - 1; ++i) { - size_t v1 = q.Pop(); - CHECK(v1 >= q.Head()); + size_t v1 = q.top(); + q.pop(); + CHECK(v1 >= q.top()); } } @@ -91,7 +93,8 @@ TEST_CASE("PriorityQueue heap sort", "[PriorityQueue]") for (size_t i = 0; i < testSize - 1; ++i) { - size_t v1 = q.Pop(); - CHECK(v1 <= q.Head()); + size_t v1 = q.top(); + q.pop(); + CHECK(v1 <= q.top()); } } \ No newline at end of file