adjacency_matrix:
* make swap accept the right type * make resize work properly
This commit is contained in:
@@ -274,7 +274,7 @@ public:
|
||||
* @brief Exchanges the contents with those of a given adjacency matrix.
|
||||
* @param other Adjacency matrix to exchange the content with.
|
||||
*/
|
||||
void swap(adjacency_matrix &other) {
|
||||
void swap(basic_adjacency_matrix &other) {
|
||||
using std::swap;
|
||||
swap(matrix, other.matrix);
|
||||
swap(vert, other.vert);
|
||||
@@ -335,8 +335,13 @@ public:
|
||||
* @param vertices The new number of vertices.
|
||||
*/
|
||||
void resize(const size_type vertices) {
|
||||
matrix.resize(vertices * vertices);
|
||||
vert = vertices;
|
||||
basic_adjacency_matrix other{vertices, get_allocator()};
|
||||
|
||||
for(auto [lhs, rhs]: edges()) {
|
||||
other.insert(lhs, rhs);
|
||||
}
|
||||
|
||||
other.swap(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
|
||||
TEST(AdjacencyMatrix, Resize) {
|
||||
entt::adjacency_matrix adjacency_matrix{2};
|
||||
adjacency_matrix.insert(0u, 1u);
|
||||
adjacency_matrix.insert(1u, 0u);
|
||||
|
||||
ASSERT_EQ(adjacency_matrix.size(), 2u);
|
||||
ASSERT_TRUE(adjacency_matrix.contains(0u, 1u));
|
||||
ASSERT_TRUE(adjacency_matrix.contains(1u, 0u));
|
||||
|
||||
adjacency_matrix.resize(3u);
|
||||
|
||||
ASSERT_EQ(adjacency_matrix.size(), 3u);
|
||||
ASSERT_TRUE(adjacency_matrix.contains(0u, 1u));
|
||||
ASSERT_TRUE(adjacency_matrix.contains(1u, 0u));
|
||||
}
|
||||
|
||||
TEST(AdjacencyMatrix, Constructors) {
|
||||
|
||||
Reference in New Issue
Block a user