Use the Koenig swap and add free swap function for DeallocationVector

This commit is contained in:
Patrick Niklaus 2015-12-16 18:12:18 +01:00
parent fd5881670d
commit ff7cb91d9c
2 changed files with 20 additions and 3 deletions

View File

@ -237,6 +237,12 @@ class DeallocatingVectorRemoveIterator
} }
}; };
template <typename ElementT, std::size_t ELEMENTS_PER_BLOCK>
class DeallocatingVector;
template<typename T, std::size_t S>
void swap(DeallocatingVector<T, S>& lhs, DeallocatingVector<T, S>& rhs);
template <typename ElementT, std::size_t ELEMENTS_PER_BLOCK = 8388608 / sizeof(ElementT)> template <typename ElementT, std::size_t ELEMENTS_PER_BLOCK = 8388608 / sizeof(ElementT)>
class DeallocatingVector class DeallocatingVector
{ {
@ -257,6 +263,8 @@ class DeallocatingVector
~DeallocatingVector() { clear(); } ~DeallocatingVector() { clear(); }
friend void swap<>(DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK>& lhs, DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK>& rhs);
void swap(DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK> &other) void swap(DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK> &other)
{ {
std::swap(current_size, other.current_size); std::swap(current_size, other.current_size);
@ -386,4 +394,10 @@ class DeallocatingVector
} }
}; };
template<typename T, std::size_t S>
void swap(DeallocatingVector<T, S>& lhs, DeallocatingVector<T, S>& rhs)
{
lhs.swap(rhs);
}
#endif /* DEALLOCATING_VECTOR_HPP */ #endif /* DEALLOCATING_VECTOR_HPP */

View File

@ -61,7 +61,8 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(
void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector<EdgeBasedEdge> &output_edge_list) void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector<EdgeBasedEdge> &output_edge_list)
{ {
BOOST_ASSERT_MSG(0 == output_edge_list.size(), "Vector is not empty"); BOOST_ASSERT_MSG(0 == output_edge_list.size(), "Vector is not empty");
std::swap(m_edge_based_edge_list, output_edge_list); using std::swap; // Koenig swap
swap(m_edge_based_edge_list, output_edge_list);
} }
void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes) void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes)
@ -75,12 +76,14 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes)
BOOST_ASSERT(m_node_info_list.at(node.v).lat != INT_MAX); BOOST_ASSERT(m_node_info_list.at(node.v).lat != INT_MAX);
} }
#endif #endif
std::swap(nodes, m_edge_based_node_list); using std::swap; // Koenig swap
swap(nodes, m_edge_based_node_list);
} }
void EdgeBasedGraphFactory::GetStartPointMarkers(std::vector<bool> &node_is_startpoint) void EdgeBasedGraphFactory::GetStartPointMarkers(std::vector<bool> &node_is_startpoint)
{ {
std::swap(m_edge_based_node_is_startpoint, node_is_startpoint); using std::swap; // Koenig swap
swap(m_edge_based_node_is_startpoint, node_is_startpoint);
} }
unsigned EdgeBasedGraphFactory::GetHighestEdgeID() unsigned EdgeBasedGraphFactory::GetHighestEdgeID()