Skip to content

Commit daa3c6a

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents 24b20cf + 0b2d647 commit daa3c6a

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/dsm/sources/AdjacencyMatrix.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ namespace dsm {
6565

6666
void AdjacencyMatrix::insert(Id row, Id col) {
6767
if (row > m_rowOffsets.size() - 2) {
68-
for (auto i = 0ul; i < row - m_rowOffsets.size() + 2; ++i) {
69-
m_rowOffsets.push_back(m_rowOffsets.back() + 1);
68+
auto n = row - m_rowOffsets.size() + 2;
69+
for (auto i = 0ul; i < n - 1; ++i) {
70+
m_rowOffsets.push_back(m_rowOffsets.back());
7071
}
72+
m_rowOffsets.push_back(m_rowOffsets.back() + 1);
7173
m_nRows = row + 1;
7274
} else {
7375
std::for_each(

test/Test_AdjacencyMatrix.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,42 @@ TEST_CASE("Test construction from edge map") {
220220
CHECK_EQ(adj, adj2);
221221
}
222222
}
223+
224+
TEST_CASE("Test insertion of random values") {
225+
AdjacencyMatrix adj;
226+
adj.insert(4, 2);
227+
auto offsets = test::offsets(adj);
228+
auto indices = test::indices(adj);
229+
CHECK_EQ(offsets.size(), 6);
230+
std::for_each(
231+
offsets.begin(), offsets.begin() + 5, [](auto value) { CHECK(value == 0); });
232+
CHECK_EQ(offsets[5], 1);
233+
CHECK_EQ(indices.size(), 1);
234+
CHECK_EQ(indices[0], 2);
235+
236+
adj.insert(63, 268);
237+
offsets = test::offsets(adj);
238+
indices = test::indices(adj);
239+
CHECK(offsets.size() == 65);
240+
std::for_each(
241+
offsets.begin() + 5, offsets.begin() + 63, [](auto value) { CHECK(value == 1); });
242+
CHECK_EQ(offsets[64], 2);
243+
CHECK_EQ(indices.size(), 2);
244+
CHECK_EQ(indices[1], 268);
245+
246+
adj.insert(2, 3);
247+
offsets = test::offsets(adj);
248+
indices = test::indices(adj);
249+
CHECK_EQ(offsets.size(), 65);
250+
CHECK_EQ(offsets[0], 0);
251+
CHECK_EQ(offsets[2], 0);
252+
CHECK_EQ(offsets[3], 1);
253+
CHECK_EQ(offsets[4], 1);
254+
CHECK_EQ(offsets[5], 2);
255+
CHECK_EQ(offsets[63], 2);
256+
CHECK_EQ(offsets[64], 3);
257+
CHECK_EQ(indices.size(), 3);
258+
CHECK_EQ(indices[0], 3);
259+
CHECK_EQ(indices[1], 2);
260+
CHECK_EQ(indices[2], 268);
261+
}

0 commit comments

Comments
 (0)