Skip to content

Commit b7a2ff8

Browse files
committed
Polish
1 parent 7c17f80 commit b7a2ff8

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

src/neighbor_partitioner.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ void NeighborPartitioner::read_more()
6969

7070
void NeighborPartitioner::read_remaining()
7171
{
72-
boost::dynamic_bitset<> &is_boundary = is_boundarys[p - 1];
73-
boost::dynamic_bitset<> &is_core = is_cores[p - 1];
72+
auto &is_boundary = is_boundarys[p - 1], &is_core = is_cores[p - 1];
7473

7574
rep (u, num_vertices)
7675
for (auto &v : adj_out[u]) {
@@ -103,17 +102,20 @@ void NeighborPartitioner::read_remaining()
103102

104103
void NeighborPartitioner::clean_samples()
105104
{
106-
rep (u, num_vertices)
107-
for (size_t i = 0; i < adj_out[u].size();) {
108-
edge_t e(u, adj_out[u][i]);
105+
rep (u, num_vertices) {
106+
adjlist_t &neighbors = adj_out[u];
107+
for (size_t i = 0; i < neighbors.size();) {
108+
vid_t &v = neighbors[i];
109+
edge_t e(u, v);
109110
if (!check_edge(&e)) {
110111
sample_size--;
111-
erase_one(adj_in[adj_out[u][i]], u);
112-
std::swap(adj_out[u][i], adj_out[u].back());
113-
adj_out[u].pop_back();
112+
erase_one(adj_in[v], u);
113+
std::swap(v, neighbors.back());
114+
neighbors.pop_back();
114115
} else
115116
i++;
116117
}
118+
}
117119
}
118120

119121
size_t NeighborPartitioner::count_mirrors()

src/neighbor_partitioner.hpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
class NeighborPartitioner
1919
{
2020
private:
21-
typedef std::vector<std::vector<vid_t>> adjlist_t;
21+
typedef std::vector<vid_t> adjlist_t;
22+
typedef std::vector<adjlist_t> graph_t;
2223

2324
std::string basefilename;
2425

@@ -34,7 +35,7 @@ class NeighborPartitioner
3435
off_t filesize;
3536
char *fin_map, *fin_ptr, *fin_end;
3637

37-
adjlist_t adj_out, adj_in;
38+
graph_t adj_out, adj_in;
3839
MinHeap<vid_t, vid_t> min_heap;
3940
std::vector<size_t> occupied;
4041
std::vector<vid_t> degrees;
@@ -47,22 +48,24 @@ class NeighborPartitioner
4748
bool check_edge(const edge_t *e)
4849
{
4950
rep (i, bucket) {
50-
if (is_boundarys[i][e->first] && is_boundarys[i][e->second] &&
51+
auto &is_boundary = is_boundarys[i];
52+
if (is_boundary[e->first] && is_boundary[e->second] &&
5153
occupied[i] < capacity) {
5254
assign_edge(i, e->first, e->second);
5355
return false;
5456
}
5557
}
5658

5759
rep (i, bucket) {
58-
if ((is_cores[i][e->first] || is_cores[i][e->second]) &&
60+
auto &is_core = is_cores[i], &is_boundary = is_boundarys[i];
61+
if ((is_core[e->first] || is_core[e->second]) &&
5962
occupied[i] < capacity) {
60-
if (is_cores[i][e->first] && degrees[e->second] > average_degree)
63+
if (is_core[e->first] && degrees[e->second] > average_degree)
6164
continue;
62-
if (is_cores[i][e->second] && degrees[e->first] > average_degree)
65+
if (is_core[e->second] && degrees[e->first] > average_degree)
6366
continue;
64-
is_boundarys[i][e->first] = true;
65-
is_boundarys[i][e->second] = true;
67+
is_boundary[e->first] = true;
68+
is_boundary[e->second] = true;
6669
assign_edge(i, e->first, e->second);
6770
return false;
6871
}
@@ -79,7 +82,7 @@ class NeighborPartitioner
7982
degrees[to]--;
8083
}
8184

82-
void erase_one(std::vector<vid_t> &neighbors, const vid_t &v)
85+
void erase_one(adjlist_t &neighbors, const vid_t &v)
8386
{
8487
for (size_t i = 0; i < neighbors.size(); )
8588
if (neighbors[i] == v) {
@@ -91,7 +94,7 @@ class NeighborPartitioner
9194
LOG(FATAL) << "reverse edge not found";
9295
}
9396

94-
size_t erase(std::vector<vid_t> &neighbors, const vid_t &v)
97+
size_t erase(adjlist_t &neighbors, const vid_t &v)
9598
{
9699
size_t count = 0;
97100
for (size_t i = 0; i < neighbors.size(); )
@@ -106,8 +109,7 @@ class NeighborPartitioner
106109

107110
void add_boundary(vid_t vid)
108111
{
109-
boost::dynamic_bitset<> &is_core = is_cores[bucket];
110-
boost::dynamic_bitset<> &is_boundary = is_boundarys[bucket];
112+
auto &is_core = is_cores[bucket], &is_boundary = is_boundarys[bucket];
111113

112114
if (is_boundary[vid])
113115
return;
@@ -118,23 +120,24 @@ class NeighborPartitioner
118120
}
119121

120122
rep (direction, 2) {
121-
std::vector<vid_t> &adj = direction ? adj_out[vid] : adj_in[vid];
122-
adjlist_t &adj_r = direction ? adj_in : adj_out;
123-
for (size_t i = 0; i < adj.size();) {
124-
if (is_core[adj[i]]) {
123+
adjlist_t &neighbors = direction ? adj_out[vid] : adj_in[vid];
124+
graph_t &adj_r = direction ? adj_in : adj_out;
125+
for (size_t i = 0; i < neighbors.size();) {
126+
vid_t &u = neighbors[i];
127+
if (is_core[u]) {
125128
sample_size--;
126-
assign_edge(bucket, direction ? vid : adj[i], direction ? adj[i] : vid);
129+
assign_edge(bucket, direction ? vid : u, direction ? u : vid);
127130
min_heap.decrease_key(vid);
128-
std::swap(adj[i], adj.back());
129-
adj.pop_back();
130-
} else if (is_boundary[adj[i]] && occupied[bucket] < local_capacity) {
131+
std::swap(u, neighbors.back());
132+
neighbors.pop_back();
133+
} else if (is_boundary[u] && occupied[bucket] < local_capacity) {
131134
sample_size--;
132-
assign_edge(bucket, direction ? vid : adj[i], direction ? adj[i] : vid);
135+
assign_edge(bucket, direction ? vid : u, direction ? u : vid);
133136
min_heap.decrease_key(vid);
134-
erase_one(adj_r[adj[i]], vid);
135-
min_heap.decrease_key(adj[i]);
136-
std::swap(adj[i], adj.back());
137-
adj.pop_back();
137+
erase_one(adj_r[u], vid);
138+
min_heap.decrease_key(u);
139+
std::swap(u, neighbors.back());
140+
neighbors.pop_back();
138141
} else
139142
i++;
140143
}

0 commit comments

Comments
 (0)