summaryrefslogtreecommitdiff
path: root/lib/src
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-11-21 19:10:22 -0500
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-11-21 19:10:22 -0500
commit66aad9c05bce441e3f74049b6c055312287e6a4a (patch)
tree8f59618ad1a627132169838fb7976266d3f156fe /lib/src
parent2254561ab1a3c1ac41d3c7a72b1b9d72079d6084 (diff)
downloadfuse_networks-66aad9c05bce441e3f74049b6c055312287e6a4a.tar.gz
fuse_networks-66aad9c05bce441e3f74049b6c055312287e6a4a.tar.bz2
fuse_networks-66aad9c05bce441e3f74049b6c055312287e6a4a.zip
slightly friendlier graph initialization
Diffstat (limited to 'lib/src')
-rw-r--r--lib/src/graph.cpp23
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});
+ }
}
}