-
Notifications
You must be signed in to change notification settings - Fork 12
/
validate.h
76 lines (70 loc) · 1.92 KB
/
validate.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
#include "comm.h"
template < typename index_t,
typename vertex_t,
typename depth_t>
index_t validate(
depth_t *depth_h,
vertex_t *adj_list,
index_t *adj_card,
index_t *beg_pos,
index_t vert_count)
{
//divide the adjacency vertices of this vertex into two parts
//-parent part: all the vertices connected to the parent part
// should have smaller or equal to base_depth
//-children part: all vertices connected to the children part
// should have larger or equal to base_depth
//depth difference should be no more than 1
depth_t base_depth;
char err_type;
for(int i = 0; i< vert_count; i++){
base_depth = depth_h[i];
if(base_depth ==INFTY) continue;
if(!base_depth){//src vertex
for(int j = beg_pos[i]; j< beg_pos[i]+adj_card[i]; j++)
if((depth_h[adj_list[j]]!= 1) && (adj_list[j]!=i)){
std::cout<<"Vert: "<<adj_list[j]
<<" depth: "<<(int)depth_h[adj_list[j]]<<"\n";
return -1;
}
}else{
//neighbor should consist both parents and children
err_type = 0x00;//0x00000011
// ||
// |+----child bit
// +-----parent bit
//
for(int j = beg_pos[i]; j<beg_pos[i]+adj_card[i]; j++){
if(depth_h[adj_list[j]] == base_depth - 1)
if(!(err_type & 0x02)) err_type |=0x02;
else if(depth_h[adj_list[j]] == base_depth + 1)
if(!(err_type & 0x01)) err_type |=0x01;
else if(depth_h[adj_list[j]] != base_depth)
return -2;
}
if(err_type == 0x01){
std::cout<<"Vert: "<<i<<" err: "<<(int)err_type<<"\n";
return -3;
}
}
}
return 0;
}
template< typename vertex_t,
typename index_t,
typename depth_t>
void report(
index_t &agg_tr_edges,
index_t &agg_tr_v,
depth_t *depth_h,
index_t *adj_card,
index_t vert_count)
{
agg_tr_edges = 0;
agg_tr_v = 0;
for(index_t i = 0; i< vert_count; i++)
if(depth_h[i] != INFTY){
agg_tr_v ++;
agg_tr_edges += adj_card[i];
}
}