-
Notifications
You must be signed in to change notification settings - Fork 37
Replace PriorityQueue class with it's stl equivalent #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| AllNodes.push_back(s); | ||
| openList.Push(std::make_pair(AllNodes.size() - 1, s.TotalCost())); | ||
| openList.push(std::make_pair(AllNodes.size() - 1, s.TotalCost())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider constructing element in-place with emplace, this applies to whole PR
MuniuDev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job. Consider applying @JDuchniewicz comment. LGTM
| std::vector<::pe::core::storage::PriorityQueue<std::pair<u8, float>, std::function<bool(const std::pair<u8, float>&, const std::pair<u8, float>&)>>> tmpBonesList; | ||
| tmpBonesList.resize(mesh->mNumVertices, { [](const std::pair<u8, float>& v1, const std::pair<u8, float>& v2) { return v1.second > v2.second; } }); | ||
|
|
||
| std::vector<std::priority_queue<std::pair<u8, float>,std::vector<std::pair<u8, float>>, std::function<bool(const std::pair<u8, float>&, const std::pair<u8, float>&)>>> tmpBonesList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that's a mouthful. Nice job though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about usings for this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually a good idea. Let's do it.
|
One comment, emplace create object in place in the container. Thus when changing it from push to emplace replace this: |
| if (meshCmp->GetBlendingMode() == eBlendingMode::OPAUQE) | ||
| { | ||
| sceneView.OpaqueQueue.push(meshCmp); | ||
| sceneView.OpaqueQueue.emplace(meshCmp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you're not constructing object inside or right before push, don't bother with emplace.
It's actually a decline in performance.
| size_t vertId = vertWeight.mVertexId; | ||
| float weight = vertWeight.mWeight; | ||
| tmpBonesList[vertId].push({ boneId, weight }); | ||
| tmpBonesList[vertId].emplace(std::pair<u8, float>( boneId, weight )); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using emplace in such cases is good, just don't call the constructor, emplace will call it for you. Just provide it with constructor's arguments.
| { | ||
| if(m_ttlEnabled && !enabled) | ||
| { | ||
| bool bResult = m_ttlEntries.empty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what to do here i keep getting "discarding return value of function with 'nodiscard' attribute queue.empty()" warning which is then treated as error by compiler
| if(m_ttlEnabled && !enabled) | ||
| { | ||
| m_ttlEntries.Clear(); | ||
| DISCARD m_ttlEntries.empty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not clearing the queue. Replace with m_ttlEntries.c.clear()
|
|
||
| AllNodes.push_back(PathNode(startNode, 0, graph->GetHeuristicCost(startNode, destNode) )); | ||
| openList.Push(std::make_pair(AllNodes.size() - 1, graph->GetHeuristicCost(startNode, destNode))); | ||
| openList.emplace(std::make_pair(AllNodes.size() - 1, graph->GetHeuristicCost(startNode, destNode))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for make_pair here, since we have emplace.
|
|
||
| AllNodes.push_back(s); | ||
| openList.Push(std::make_pair(AllNodes.size() - 1, s.TotalCost())); | ||
| openList.emplace(std::make_pair(AllNodes.size() - 1, s.TotalCost())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for make_pair here, since we have emplace.
| } | ||
|
|
||
| closedList.Push(std::make_pair(qIdx, AllNodes[qIdx].TotalCost())); | ||
| closedList.emplace(std::make_pair(qIdx, AllNodes[qIdx].TotalCost())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for make_pair here, since we have emplace.
| if(m_ttlEnabled && !enabled) | ||
| { | ||
| DISCARD m_ttlEntries.empty(); | ||
| std::swap(m_ttlEntries, std::priority_queue<TTLEntry>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not compile because you are trying to swap into a temporary (rvalue) and unless it is called as member function as shown here it won't.
Why just not call clear on the m_ttlEntries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe stl priority queue doesn't have clear method.
| CHECK(q.size() == i+1); | ||
| } | ||
|
|
||
| for (int i = testSize-1; i >= 0; --i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any preference for spacings in such cases?
| } | ||
| } | ||
|
|
||
| TEST_CASE("PriorityQueue reverrse sorted push test", "[PriorityQueue]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spelling
|
|
||
| namespace pe::core::storage | ||
| { | ||
| template<class _Ty,class _Pr = std::less<typename std::vector<_Ty>::value_type> > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would stick to normal engine conventions for template parameters, underscores are better left off in the stl implementation
| @@ -1,5 +1,6 @@ | |||
| #include <pe/core/storage/impl/IndexedStringManager.hpp> | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary newline
No description provided.