-
Notifications
You must be signed in to change notification settings - Fork 1
/
newGraph.h
619 lines (548 loc) · 25 KB
/
newGraph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
#ifndef SPEEDPPR_GRAPH_H
#define SPEEDPPR_GRAPH_H
#ifndef USE_REVERSE_POS
#define USE_REVERSE_POS
#endif
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>
#include <fstream>
#include <queue>
#include <cstring>
#include <iostream>
#include <iterator>
#include <chrono>
#include <mylib.h>
typedef int VertexIdType;
typedef int EdgeSizeType;
typedef double PageRankScoreType;
vector<double> speed_residue;
vector<double> speed_reserve;
template<class FLOAT_TYPE>
struct IdScorePair {
VertexIdType id = 0;
FLOAT_TYPE score = 0;
IdScorePair(const VertexIdType &_id = 0, const FLOAT_TYPE &_score = 0) :
id(_id), score(_score) {}
};
template<class FLOAT_TYPE>
struct IdScorePairComparatorGreater {
// Compare 2 IdScorePair objects using name
bool operator()(const IdScorePair<FLOAT_TYPE> &pair1, const IdScorePair<FLOAT_TYPE> &pair2) {
return pair1.score > pair2.score || pair1.score == pair2.score && pair1.id < pair2.id;
}
};
template<class FLOAT_TYPE>
struct IdScorePairComparatorLess {
// Compare 2 IdScorePair objects using name
bool operator()(const IdScorePair<FLOAT_TYPE> &pair1, const IdScorePair<FLOAT_TYPE> &pair2) {
return pair1.score < pair2.score || pair1.score == pair2.score && pair1.id < pair2.id;
}
};
typedef std::priority_queue<IdScorePair<float>, std::vector<IdScorePair<float> >, IdScorePairComparatorGreater<float> > IdScorePairMaxQueue_float;
struct Edge {
VertexIdType from_id;
VertexIdType to_id;
Edge() : from_id(0), to_id(0) {}
Edge(const VertexIdType &_from, const VertexIdType &_to) :
from_id(_from), to_id(_to) {}
bool operator<(const Edge &_edge) const {
return from_id < _edge.from_id || (from_id == _edge.from_id && to_id < _edge.to_id);
}
};
class NewGraph {
private:
VertexIdType numOfVertices = 0;
EdgeSizeType numOfEdges = 0;
VertexIdType num_deadend_vertices = 0;
VertexIdType sid = 0;
VertexIdType dummy_id = 0;
PageRankScoreType alpha = 0.2;
EdgeSizeType max_size_edge_list = 0;
std::vector<VertexIdType> out_degrees;
std::vector<VertexIdType> in_degrees;
std::vector<VertexIdType> start_pos_in_out_neighbor_lists;
std::vector<VertexIdType> start_pos_in_appearance_pos_lists;
std::vector<VertexIdType> out_neighbors_lists;
std::vector<VertexIdType> appearance_pos_lists;
std::vector<VertexIdType> deadend_vertices;
public:
inline size_t get_num_dead_end() const {
return deadend_vertices.size();
}
inline void set_dummy_out_degree_zero() {
out_degrees[dummy_id] = 0;
start_pos_in_out_neighbor_lists[dummy_id + 1] = start_pos_in_out_neighbor_lists[dummy_id];
}
inline void set_dummy_neighbor(const VertexIdType &_id) {
out_degrees[dummy_id] = 1;
start_pos_in_out_neighbor_lists[dummy_id + 1] = start_pos_in_out_neighbor_lists[dummy_id] + 1;
out_neighbors_lists[start_pos_in_out_neighbor_lists[dummy_id]] = _id;
}
inline void reset_set_dummy_neighbor() {
out_degrees[dummy_id] = 0;
out_neighbors_lists[start_pos_in_out_neighbor_lists[dummy_id]] = dummy_id;
set_dummy_out_degree_zero();
}
inline void update(VertexIdType u, VertexIdType v) {
VertexIdType index = start_pos_in_out_neighbor_lists[u];
out_neighbors_lists.emplace(out_neighbors_lists.begin() + index, v);
for (VertexIdType node = u + 1; node < numOfVertices + 2; node ++){
start_pos_in_out_neighbor_lists[node] = start_pos_in_out_neighbor_lists[node] + 1;
}
index = start_pos_in_appearance_pos_lists[v];
appearance_pos_lists.emplace(appearance_pos_lists.begin() + index, u);
for (VertexIdType node = v + 1; node < numOfVertices + 2; node ++){
start_pos_in_appearance_pos_lists[node] = start_pos_in_appearance_pos_lists[node] + 1;
}
}
inline const VertexIdType &get_dummy_id() const {
return dummy_id;
}
inline const VertexIdType &get_sid() const {
return sid;
}
inline const PageRankScoreType &get_alpha() const {
return alpha;
}
inline void set_alpha(const PageRankScoreType _alpha = 0.2) {
alpha = _alpha;
}
inline void fill_dead_end_neighbor_with_id(const VertexIdType &_id) {
for (VertexIdType index = 0; index < num_deadend_vertices; ++index) {
const VertexIdType &id = deadend_vertices[index];
const VertexIdType &start = start_pos_in_out_neighbor_lists[id];
out_neighbors_lists[start] = _id;
}
}
inline void change_in_neighbors_adj(const VertexIdType &_sid, const VertexIdType &_target) {
const VertexIdType &idx_start = start_pos_in_appearance_pos_lists[_sid];
const VertexIdType &idx_end = start_pos_in_appearance_pos_lists[_sid + 1];
for (VertexIdType index = idx_start; index < idx_end; ++index) {
out_neighbors_lists[appearance_pos_lists[index]] = _target;
}
}
inline void restore_neighbors_adj(const VertexIdType &_sid) {
const VertexIdType &idx_start = start_pos_in_appearance_pos_lists[_sid];
const VertexIdType &idx_end = start_pos_in_appearance_pos_lists[_sid + 1];
for (VertexIdType index = idx_start; index < idx_end; ++index) {
out_neighbors_lists[appearance_pos_lists[index]] = _sid;
}
}
inline void set_source_and_alpha(const VertexIdType _sid, const PageRankScoreType _alpha) {
sid = _sid;
alpha = _alpha;
// fill_dead_end_neighbor_with_id(_sid);
}
NewGraph() = default;
~NewGraph() = default;
inline const VertexIdType &getNumOfVertices() const {
return numOfVertices;
}
/**
* @param _vid
* @return return the original out degree
*/
inline const VertexIdType &original_out_degree(const VertexIdType &_vid) const {
assert(_vid < numOfVertices);
return out_degrees[_vid];
}
inline const VertexIdType &get_neighbor_list_start_pos(const VertexIdType &_vid) const {
assert(_vid < numOfVertices + 2);
return start_pos_in_out_neighbor_lists[_vid];
}
inline const VertexIdType &get_in_neighbor_list_start_pos(const VertexIdType &_vid) const {
assert(_vid < numOfVertices + 2);
return start_pos_in_appearance_pos_lists[_vid];
}
inline const VertexIdType &getOutNeighbor(const VertexIdType &_index) const {
// if (_index >= start_pos_in_out_neighbor_lists[dummy_id + 1]) {
// MSG("Time to check " __FILE__)
// MSG(__LINE__)
// }
assert(_index < start_pos_in_out_neighbor_lists[dummy_id + 1]);
return out_neighbors_lists[_index];
}
inline const VertexIdType &getInNeighbor(const VertexIdType &_index) const {
assert(_index < start_pos_in_appearance_pos_lists[dummy_id + 1]);
return appearance_pos_lists[_index];
}
inline const EdgeSizeType &getNumOfEdges() const {
return numOfEdges;
}
void read_binary(const std::string &_attribute_file,
const std::string &_graph_file) {
{
std::string line;
std::ifstream attribute_file(_attribute_file);
if (attribute_file.is_open()) {
std::getline(attribute_file, line);
size_t start1 = line.find_first_of('=');
numOfVertices = std::stoul(line.substr(start1 + 1));
std::getline(attribute_file, line);
size_t start2 = line.find_first_of('=');
numOfEdges = std::stoul(line.substr(start2 + 1));
dummy_id = numOfVertices;
printf("The Number of Vertices: %d\n", numOfVertices);
printf("The Number of Edges: %d\n", numOfEdges);
attribute_file.close();
} else {
printf(__FILE__ "; LINE %d; File Not Exists.\n", __LINE__);
std::cout << _attribute_file << std::endl;
exit(1);
}
}
//const auto start = getCurrentTime();
// create temporary graph
std::vector<Edge> edges(numOfEdges);
if (std::FILE *f = std::fopen(_graph_file.c_str(), "rb")) {
size_t rtn = std::fread(edges.data(), sizeof edges[0], edges.size(), f);
printf("Returned Value of fread: %zu\n", rtn);
std::fclose(f);
} else {
printf("Graph::read; File Not Exists.\n");
std::cout << _graph_file << std::endl;
exit(1);
}
//const auto end = getCurrentTime();
//printf("Time Used For Loading BINARY : %.2f\n", end - start);
// read the edges
// the ids must be in the range from [0 .... the number of vertices - 1];
numOfEdges = 0;
out_degrees.clear();
out_degrees.resize(numOfVertices + 2, 0);
in_degrees.clear();
in_degrees.resize(numOfVertices + 2, 0);
for (auto &edge : edges) {
const VertexIdType &from_id = edge.from_id;
const VertexIdType &to_id = edge.to_id;
// remove self loop
if (from_id != to_id) {
//the edge read is a directed one
++out_degrees[from_id];
++in_degrees[to_id];
++numOfEdges;
}
}
/* final count */
// printf("%d-th Directed Edge Processed.\n", numOfEdges);
// sort the adj list
// for (auto &neighbors : matrix) {
// std::sort(neighbors.begin(), neighbors.end());
// }
// process the dead_end
VertexIdType degree_max = 0;
deadend_vertices.clear();
for (VertexIdType i = 0; i < numOfVertices; ++i) {
if (out_degrees[i] == 0) {
deadend_vertices.emplace_back(i);
}
degree_max = std::max(degree_max, out_degrees[i]);
}
num_deadend_vertices = deadend_vertices.size();
printf("The number of dead end vertices:%d\n", num_deadend_vertices);
// process pos_list list
start_pos_in_appearance_pos_lists.clear();
start_pos_in_appearance_pos_lists.resize(numOfVertices + 2, 0);
for (VertexIdType i = 0, j = 1; j < numOfVertices; ++i, ++j) {
start_pos_in_appearance_pos_lists[j] = start_pos_in_appearance_pos_lists[i] + in_degrees[i];
}
start_pos_in_appearance_pos_lists[numOfVertices] = numOfEdges;
// process out list
start_pos_in_out_neighbor_lists.clear();
start_pos_in_out_neighbor_lists.resize(numOfVertices + 2, 0);
for (VertexIdType current_id = 0, next_id = 1; next_id < numOfVertices + 1; ++current_id, ++next_id) {
start_pos_in_out_neighbor_lists[next_id] =
start_pos_in_out_neighbor_lists[current_id] + std::max(out_degrees[current_id], 1);
}
// process dummy vertex
assert(start_pos_in_out_neighbor_lists[numOfVertices] == numOfEdges + deadend_vertices.size());
out_degrees[dummy_id] = 0;
start_pos_in_out_neighbor_lists[numOfVertices + 1] = start_pos_in_out_neighbor_lists[numOfVertices];
////////////////////////////////////////////////////////////
// compute the positions
std::vector<VertexIdType> out_positions_to_fill(start_pos_in_out_neighbor_lists.begin(),
start_pos_in_out_neighbor_lists.end());
// fill the edge list
out_neighbors_lists.clear();
out_neighbors_lists.resize(numOfEdges + num_deadend_vertices + degree_max, 0);
uint32_t edges_processed = 0;
uint32_t msg_gap = std::max(1, numOfEdges / 10);
std::vector<std::pair<VertexIdType, VertexIdType>> position_pair;
position_pair.reserve(numOfEdges);
for (auto &edge : edges) {
const VertexIdType &from_id = edge.from_id;
const VertexIdType &to_id = edge.to_id;
// remove self loop
if (from_id != to_id) {
VertexIdType &out_position = out_positions_to_fill[from_id];
assert(out_position < out_positions_to_fill[from_id + 1]);
out_neighbors_lists[out_position] = to_id;
position_pair.emplace_back(to_id, out_position);
++out_position;
if (++edges_processed % msg_gap == 0) {
printf("%u edges processed.\n", edges_processed);
}
}
}
edges.clear();
printf("%s\n", std::string(30, '-').c_str());
#ifdef USE_REVERSE_POS
std::vector<VertexIdType> in_positions_to_fill(start_pos_in_appearance_pos_lists.begin(),
start_pos_in_appearance_pos_lists.end());
in_positions_to_fill[numOfVertices] = numOfEdges;
//const double time_sort_start = getCurrentTime();
std::sort(position_pair.begin(), position_pair.end(),
[](pair<VertexIdType, VertexIdType> const& l, pair<VertexIdType, VertexIdType> const& r){return l.first < r.first;});
//const double time_sort_end = getCurrentTime();
// MSG(time_sort_end - time_sort_start);
printf("%s\n", std::string(30, '-').c_str());
appearance_pos_lists.clear();
appearance_pos_lists.resize(numOfEdges + num_deadend_vertices + degree_max, 0);
uint32_t in_pos_pair = 0;
for (const auto &pair : position_pair) {
const VertexIdType &to_id = pair.first;
const VertexIdType &pos = pair.second;
VertexIdType &in_position = in_positions_to_fill[to_id];
assert(in_position < in_positions_to_fill[to_id + 1]);
appearance_pos_lists[in_position] = pos;
++in_position;
}
#endif
// fill the dummy ids
for (const VertexIdType &id : deadend_vertices) {
out_neighbors_lists[out_positions_to_fill[id]++] = dummy_id;
}
#ifdef DEBUG_MODE
// show();
// sanity check
// std::memcpy(in_positions_to_fill.data(), start_pos_in_appearance_pos_lists.data(),
// sizeof(VertexIdType) * numOfVertices);
// for (uint32_t index = 0; index < numOfEdges + num_deadend_vertices; ++index) {
// const VertexIdType id = out_neighbors_lists[index];
// if (id != numOfVertices) {
// VertexIdType &in_position = in_positions_to_fill[id];
// if (appearance_pos_lists[in_position] != index) {
// printf("Error in " __FILE__ ", line %d, in position error.\n", __LINE__);
// MSG(index);
// MSG(id);
// MSG(in_position);
// exit(1);
// }
// ++in_position;
// }
// }
#endif
//const double time_end = getCurrentTime();
//printf("Graph Build Finished. TIME: %.4f\n", time_end - start);
printf("%s\n", std::string(110, '-').c_str());
}
void read_file(const std::string &_attribute_file,
const std::string &_graph_file) {
{
std::string line;
std::ifstream attribute_file(_attribute_file);
if (attribute_file.is_open()) {
std::getline(attribute_file, line);
size_t start1 = line.find_first_of('=');
numOfVertices = std::stoul(line.substr(start1 + 1));
std::getline(attribute_file, line);
size_t start2 = line.find_first_of('=');
numOfEdges = std::stoul(line.substr(start2 + 1));
dummy_id = numOfVertices;
printf("The Number of Vertices: %d\n", numOfVertices);
printf("The Number of Edges: %d\n", numOfEdges);
attribute_file.close();
} else {
printf(__FILE__ "; LINE %d; File Not Exists.\n", __LINE__);
std::cout << _attribute_file << std::endl;
exit(1);
}
}
//const auto start = getCurrentTime();
// create temporary graph
std::vector<Edge> edges;
edges.reserve(numOfEdges);
std::ifstream inf(_graph_file.c_str());
if (!inf.is_open()) {
printf("CleanGraph::clean_graph; File not exists.\n");
printf("%s\n", _graph_file.c_str());
exit(1);
}
printf("\nReading Input Graph\n");
std::string line;
while (std::getline(inf, line) && line[0] == '#') {}
if (line.empty() || !isdigit(line[0])) {
printf("Error in CleanGraph::clean_graph. Raw File Format Error.\n");
printf("%s\n", line.c_str());
exit(1);
}
size_t num_lines = 0;
{
VertexIdType fromId, toID;
++num_lines;
size_t end = 0;
fromId = std::stoul(line, &end);
toID = std::stoul(line.substr(end));
// remove self-loops
edges.emplace_back(Edge(fromId, toID));
}
// read the edges
for (VertexIdType fromId, toID; inf >> fromId >> toID;) {
edges.emplace_back(Edge(fromId, toID));
if (++num_lines % 5000000 == 0) { printf("%zu Valid Lines Read.\n", num_lines); }
}
//const auto end = getCurrentTime();
//printf("Time Used For Loading BINARY : %.2f\n", end - start);
// read the edges
// the ids must be in the range from [0 .... the number of vertices - 1];
numOfEdges = 0;
out_degrees.clear();
out_degrees.resize(numOfVertices + 2, 0);
in_degrees.clear();
in_degrees.resize(numOfVertices + 2, 0);
for (auto &edge : edges) {
const VertexIdType &from_id = edge.from_id;
const VertexIdType &to_id = edge.to_id;
// remove self loop
if (from_id != to_id) {
//the edge read is a directed one
++out_degrees[from_id];
++in_degrees[to_id];
++numOfEdges;
}
}
/* final count */
// printf("%d-th Directed Edge Processed.\n", numOfEdges);
// sort the adj list
// for (auto &neighbors : matrix) {
// std::sort(neighbors.begin(), neighbors.end());
// }
// process the dead_end
VertexIdType degree_max = 0;
deadend_vertices.clear();
for (VertexIdType i = 0; i < numOfVertices; ++i) {
if (out_degrees[i] == 0) {
deadend_vertices.emplace_back(i);
}
degree_max = std::max(degree_max, out_degrees[i]);
}
num_deadend_vertices = deadend_vertices.size();
printf("The number of dead end vertices:%d\n", num_deadend_vertices);
// process pos_list list
start_pos_in_appearance_pos_lists.clear();
start_pos_in_appearance_pos_lists.resize(numOfVertices + 2, 0);
for (VertexIdType i = 0, j = 1; j < numOfVertices; ++i, ++j) {
start_pos_in_appearance_pos_lists[j] = start_pos_in_appearance_pos_lists[i] + in_degrees[i];
}
start_pos_in_appearance_pos_lists[numOfVertices] = numOfEdges;
// process out list
start_pos_in_out_neighbor_lists.clear();
start_pos_in_out_neighbor_lists.resize(numOfVertices + 2, 0);
for (VertexIdType current_id = 0, next_id = 1; next_id < numOfVertices + 1; ++current_id, ++next_id) {
start_pos_in_out_neighbor_lists[next_id] =
start_pos_in_out_neighbor_lists[current_id] + std::max(out_degrees[current_id], 1);
}
// process dummy vertex
assert(start_pos_in_out_neighbor_lists[numOfVertices] == numOfEdges + deadend_vertices.size());
out_degrees[dummy_id] = 0;
start_pos_in_out_neighbor_lists[numOfVertices + 1] = start_pos_in_out_neighbor_lists[numOfVertices];
////////////////////////////////////////////////////////////
// compute the positions
std::vector<VertexIdType> out_positions_to_fill(start_pos_in_out_neighbor_lists.begin(),
start_pos_in_out_neighbor_lists.end());
// fill the edge list
out_neighbors_lists.clear();
out_neighbors_lists.resize(numOfEdges + num_deadend_vertices + degree_max, 0);
uint32_t edges_processed = 0;
uint32_t msg_gap = std::max(1, numOfEdges / 10);
std::vector<std::pair<VertexIdType, VertexIdType>> position_pair;
position_pair.reserve(numOfEdges);
for (auto &edge : edges) {
const VertexIdType &from_id = edge.from_id;
const VertexIdType &to_id = edge.to_id;
// remove self loop
if (from_id != to_id) {
VertexIdType &out_position = out_positions_to_fill[from_id];
assert(out_position < out_positions_to_fill[from_id + 1]);
out_neighbors_lists[out_position] = to_id;
position_pair.emplace_back(to_id, from_id);
++out_position;
if (++edges_processed % msg_gap == 0) {
printf("%u edges processed.\n", edges_processed);
}
}
}
edges.clear();
printf("%s\n", std::string(30, '-').c_str());
#ifdef USE_REVERSE_POS
std::vector<VertexIdType> in_positions_to_fill(start_pos_in_appearance_pos_lists.begin(),
start_pos_in_appearance_pos_lists.end());
in_positions_to_fill[numOfVertices] = numOfEdges;
//const double time_sort_start = getCurrentTime();
std::sort(position_pair.begin(), position_pair.end(),
[](pair<VertexIdType, VertexIdType> const& l, pair<VertexIdType, VertexIdType> const& r){return l.first < r.first;});
//const double time_sort_end = getCurrentTime();
// MSG(time_sort_end - time_sort_start);
printf("%s\n", std::string(30, '-').c_str());
appearance_pos_lists.clear();
appearance_pos_lists.resize(numOfEdges + num_deadend_vertices + degree_max, 0);
uint32_t in_pos_pair = 0;
for (const auto &pair : position_pair) {
const VertexIdType &to_id = pair.first;
const VertexIdType &pos = pair.second;
VertexIdType &in_position = in_positions_to_fill[to_id];
assert(in_position < in_positions_to_fill[to_id + 1]);
appearance_pos_lists[in_position] = pos;
++in_position;
}
#endif
// fill the dummy ids
for (const VertexIdType &id : deadend_vertices) {
out_neighbors_lists[out_positions_to_fill[id]++] = dummy_id;
}
}
/*
void show() const {
// we need to show the dummy
const VertexIdType num_to_show = std::min(numOfVertices + 1, 50u);
// show the first elements
show_vector("The Out Degrees of The Vertices:",
std::vector<VertexIdType>(out_degrees.data(), out_degrees.data() + num_to_show));
show_vector("The Start Positions of The Vertices in Out Neighbor Lists:",
std::vector<VertexIdType>(start_pos_in_out_neighbor_lists.data(),
start_pos_in_out_neighbor_lists.data() + num_to_show));
show_vector("The In Degrees of The Vertices:",
std::vector<VertexIdType>(in_degrees.data(), in_degrees.data() + num_to_show));
show_vector("The Start Positions of The Vertices in Appearance List:",
std::vector<VertexIdType>(start_pos_in_appearance_pos_lists.data(),
start_pos_in_appearance_pos_lists.data() + num_to_show));
// assume that the number of vertices >= the number of edges; otherwise, there is a potential bug here.
show_vector("Out Neighbor Lists:",
std::vector<VertexIdType>(out_neighbors_lists.data(),
out_neighbors_lists.data() +
std::min(numOfEdges + num_deadend_vertices, 50u)));
show_vector("The Appearance Positions of Vertices in the Out Neighbor Lists:",
std::vector<VertexIdType>(appearance_pos_lists.data(),
appearance_pos_lists.data() + std::min(numOfEdges, 50u)));
// show_vector("The adj list of the middel vertex", matrix[numOfVertices / 2]);
printf("The position the id appears in outNeighbor List:\n");
for (VertexIdType id = 0; id < numOfVertices; ++id) {
const VertexIdType &idx_start = start_pos_in_appearance_pos_lists[id];
const VertexIdType &idx_end = start_pos_in_appearance_pos_lists[id + 1];
printf("Id:%u;\tPositions: ", id);
for (VertexIdType index = idx_start; index < idx_end; ++index) {
printf("%u, ", appearance_pos_lists[index]);
}
printf("\n");
}
show_vector("Dead End Vertices List:",
std::vector<VertexIdType>(deadend_vertices.data(),
deadend_vertices.data() +
std::min(num_deadend_vertices, 50u)));
printf("\n%s\n", std::string(120, '=').c_str());
}
*/
};
#endif //SPEEDPPR_GRAPH_H