diff options
Diffstat (limited to 'lib/src')
-rw-r--r-- | lib/src/graph.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp index e76947b..e5f374e 100644 --- a/lib/src/graph.cpp +++ b/lib/src/graph.cpp @@ -7,10 +7,10 @@ graph::graph(unsigned int L) { unsigned int ne = pow(L, 2); vertices.resize(nv); - edges.resize(ne); + edges.reserve(ne); dual_vertices.resize(nv); - dual_edges.resize(ne); + dual_edges.reserve(ne); for (unsigned int i = 0; i < nv; i++) { vertices[i].r.x = dx * ((1 + i / (L / 2)) % 2 + 2 * (i % (L / 2))); @@ -20,19 +20,18 @@ graph::graph(unsigned int L) { dual_vertices[i].r.y = dx * (i / (L / 2)); } - for (unsigned int i = 0; i < ne; i++) { - unsigned int x = i / L; - unsigned int y = i % L; + for (unsigned int x = 0; x < L; x++) { + for (unsigned int y = 0; y < L; y++) { + unsigned int v1 = (L * x) / 2 + ((y + x % 2) / 2) % (L / 2); + unsigned int v2 = ((L * (x + 1)) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2)) % nv; - unsigned int v1 = (L * x) / 2 + ((y + x % 2) / 2) % (L / 2); - unsigned int v2 = ((L * (x + 1)) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2)) % nv; + edges.push_back({v1, v2}); - edges[i] = {v1, v2}; + unsigned int dv1 = (L * x) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2); + unsigned int dv2 = ((L * (x + 1)) / 2 + ((y + x % 2) / 2) % (L / 2)) % nv; - unsigned int dv1 = (L * x) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2); - unsigned int dv2 = ((L * (x + 1)) / 2 + ((y + x % 2) / 2) % (L / 2)) % nv; - - dual_edges[i] = {dv1, dv2}; + dual_edges.push_back({dv1, dv2}); + } } } |