Skip to content

Commit 3c6c180

Browse files
committed
fix adjacent list bug
1 parent e5d179b commit 3c6c180

File tree

4 files changed

+82
-49
lines changed

4 files changed

+82
-49
lines changed

modules/graph/grin/c/test.c

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -946,57 +946,78 @@ void test_partition(int argc, char** argv) {
946946
}
947947

948948

949-
void test_topology_adjacent_list(int argc, char** argv) {
949+
void test_topology_structure(int argc, char** argv) {
950950
GRIN_GRAPH g = get_graph(argc, argv);
951951

952-
GRIN_VERTEX v = get_one_vertex(g);
953-
954-
GRIN_ADJACENT_LIST al = grin_get_adjacent_list(g, OUT, v);
955-
GRIN_ADJACENT_LIST_ITERATOR ali = grin_get_adjacent_list_begin(g, al);
956-
grin_destroy_adjacent_list(g, al);
957-
size_t cnt = 0;
952+
printf("vnum: %zu, enum: %zu\n", grin_get_vertex_num(g), grin_get_edge_num(g));
958953

959-
while (!grin_is_adjacent_list_end(g, ali)) {
960-
cnt++;
954+
grin_destroy_graph(g);
955+
}
961956

962-
GRIN_EDGE e = grin_get_edge_from_adjacent_list_iter(g, ali);
963-
GRIN_VERTEX v1 = grin_get_src_vertex_from_edge(g, e);
964-
if (!grin_equal_vertex(g, v, v1)) {
965-
printf("vertex not match\n");
966-
}
957+
void test_topology_adjacent_list(int argc, char** argv, GRIN_DIRECTION dir) {
958+
GRIN_GRAPH g = get_graph(argc, argv);
967959

968-
GRIN_VERTEX v2 = grin_get_dst_vertex_from_edge(g, e);
969-
GRIN_VERTEX u = grin_get_neighbor_from_adjacent_list_iter(g, ali);
970-
if (!grin_equal_vertex(g, v2, u)) {
971-
printf("vertex not match\n");
972-
}
960+
GRIN_VERTEX_LIST vl = grin_get_vertex_list(g);
961+
GRIN_VERTEX_LIST_ITERATOR vli = grin_get_vertex_list_begin(g, vl);
962+
grin_destroy_vertex_list(g, vl);
973963

974-
grin_destroy_vertex(g, v1);
975-
grin_destroy_vertex(g, v2);
976-
grin_destroy_vertex(g, u);
977-
grin_destroy_edge(g, e);
978-
grin_get_next_adjacent_list_iter(g, ali);
979-
}
964+
while (!grin_is_vertex_list_end(g, vli)) {
965+
GRIN_VERTEX v = grin_get_vertex_from_iter(g, vli);
966+
GRIN_ADJACENT_LIST al = grin_get_adjacent_list(g, dir, v);
967+
GRIN_ADJACENT_LIST_ITERATOR ali = grin_get_adjacent_list_begin(g, al);
968+
grin_destroy_adjacent_list(g, al);
980969

981-
printf("num of edge checked: %zu\n", cnt);
970+
size_t cnt = 0;
971+
while (!grin_is_adjacent_list_end(g, ali)) {
972+
cnt++;
973+
GRIN_EDGE e = grin_get_edge_from_adjacent_list_iter(g, ali);
974+
GRIN_VERTEX v1 = grin_get_src_vertex_from_edge(g, e);
975+
GRIN_VERTEX v2 = grin_get_dst_vertex_from_edge(g, e);
976+
GRIN_VERTEX u = grin_get_neighbor_from_adjacent_list_iter(g, ali);
982977

983-
grin_destroy_adjacent_list_iter(g, ali);
984-
grin_destroy_vertex(g, v);
985-
grin_destroy_graph(g);
986-
}
978+
if (dir == OUT) {
979+
if (!grin_equal_vertex(g, v, v1)) {
980+
printf("vertex not match\n");
981+
}
982+
if (!grin_equal_vertex(g, v2, u)) {
983+
printf("vertex not match\n");
984+
}
985+
} else {
986+
if (!grin_equal_vertex(g, v, v2)) {
987+
printf("vertex not match\n");
988+
}
989+
if (!grin_equal_vertex(g, v1, u)) {
990+
printf("vertex not match\n");
991+
}
992+
}
987993

988-
void test_topology_structure(int argc, char** argv) {
989-
GRIN_GRAPH g = get_graph(argc, argv);
994+
grin_destroy_vertex(g, v1);
995+
grin_destroy_vertex(g, v2);
996+
grin_destroy_vertex(g, u);
997+
grin_destroy_edge(g, e);
998+
grin_get_next_adjacent_list_iter(g, ali);
999+
}
1000+
#ifdef GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_INT64
1001+
long long int vid = grin_get_vertex_original_id_of_int64(g, v);
1002+
if (dir == OUT) {
1003+
printf("vertex %lld OUT adjacent list checked num: %zu\n", vid, cnt);
1004+
} else {
1005+
printf("vertex %lld IN adjacent list checked num: %zu\n", vid, cnt);
1006+
}
1007+
#endif
9901008

991-
printf("vnum: %zu, enum: %zu\n", grin_get_vertex_num(g), grin_get_edge_num(g));
1009+
grin_destroy_adjacent_list_iter(g, ali);
1010+
grin_destroy_vertex(g, v);
1011+
grin_get_next_vertex_list_iter(g, vli);
1012+
}
9921013

9931014
grin_destroy_graph(g);
9941015
}
9951016

996-
9971017
void test_topology(int argc, char** argv) {
9981018
test_topology_structure(argc, argv);
999-
test_topology_adjacent_list(argc, argv);
1019+
test_topology_adjacent_list(argc, argv, OUT);
1020+
test_topology_adjacent_list(argc, argv, IN);
10001021
}
10011022

10021023
int main(int argc, char** argv) {

modules/graph/grin/src/predefine.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ void __grin_init_vertex_list(_GRIN_GRAPH_T* g, GRIN_VERTEX_LIST_T* vl) {
117117
vr = g->OuterVertices(vtype);
118118
}
119119
sum += vr.size();
120-
vl->offsets.push_back(sum);
121-
vl->vrs.push_back(vr);
120+
if (sum == 0) {
121+
vl->type_begin++;
122+
} else {
123+
vl->offsets.push_back(sum);
124+
vl->vrs.push_back(vr);
125+
}
122126
}
123127
}
124128
#endif
@@ -137,8 +141,12 @@ void __grin_init_adjacent_list(_GRIN_GRAPH_T* g, GRIN_ADJACENT_LIST_T* al) {
137141
ral = g->GetOutgoingRawAdjList(_GRIN_GRAPH_T::vertex_t(al->vid), etype);
138142
}
139143
sum += ral.size();
140-
al->offsets.push_back(sum);
141-
al->data.push_back(ral);
144+
if (sum == 0) {
145+
al->etype_begin++;
146+
} else {
147+
al->offsets.push_back(sum);
148+
al->data.push_back(ral);
149+
}
142150
}
143151
}
144152
#endif

modules/graph/grin/src/topology/adjacentlist.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ GRIN_ADJACENT_LIST_ITERATOR grin_get_adjacent_list_begin(GRIN_GRAPH g, GRIN_ADJA
9090
ali->etype_end = _al->etype_end;
9191
ali->etype_current = _al->etype_begin;
9292
ali->current = 0;
93-
if (ali->dir == GRIN_DIRECTION::IN) {
94-
ali->data = _g->GetIncomingRawAdjList(_GRIN_GRAPH_T::vertex_t(ali->vid), ali->etype_current);
95-
} else {
96-
ali->data = _g->GetOutgoingRawAdjList(_GRIN_GRAPH_T::vertex_t(ali->vid), ali->etype_current);
93+
if (ali->etype_current < ali->etype_end) {
94+
if (ali->dir == GRIN_DIRECTION::IN) {
95+
ali->data = _g->GetIncomingRawAdjList(_GRIN_GRAPH_T::vertex_t(ali->vid), ali->etype_current);
96+
} else {
97+
ali->data = _g->GetOutgoingRawAdjList(_GRIN_GRAPH_T::vertex_t(ali->vid), ali->etype_current);
98+
}
9799
}
98100
return ali;
99101
}

modules/graph/grin/src/topology/vertexlist.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ GRIN_VERTEX_LIST_ITERATOR grin_get_vertex_list_begin(GRIN_GRAPH g, GRIN_VERTEX_L
6161
vli->type_current = _vl->type_begin;
6262
vli->current = 0;
6363
vli->all_master_mirror = _vl->all_master_mirror;
64-
if (vli->all_master_mirror == 0) {
65-
vli->vr = _g->Vertices(vli->type_current);
66-
} else if (vli->all_master_mirror == 1) {
67-
vli->vr = _g->InnerVertices(vli->type_current);
68-
} else {
69-
vli->vr = _g->OuterVertices(vli->type_current);
64+
if (vli->type_current < vli->type_end) {
65+
if (vli->all_master_mirror == 0) {
66+
vli->vr = _g->Vertices(vli->type_current);
67+
} else if (vli->all_master_mirror == 1) {
68+
vli->vr = _g->InnerVertices(vli->type_current);
69+
} else {
70+
vli->vr = _g->OuterVertices(vli->type_current);
71+
}
7072
}
7173
return vli;
7274
}

0 commit comments

Comments
 (0)