Skip to content

Commit 3c0367c

Browse files
committed
fix adjacent bug
1 parent 3c6c180 commit 3c0367c

File tree

4 files changed

+72
-48
lines changed

4 files changed

+72
-48
lines changed

modules/graph/grin/c/test.c

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -961,52 +961,72 @@ void test_topology_adjacent_list(int argc, char** argv, GRIN_DIRECTION dir) {
961961
GRIN_VERTEX_LIST_ITERATOR vli = grin_get_vertex_list_begin(g, vl);
962962
grin_destroy_vertex_list(g, vl);
963963

964+
GRIN_EDGE_TYPE_LIST etl = grin_get_edge_type_list(g);
965+
size_t etl_size = grin_get_edge_type_list_size(g, etl);
966+
964967
while (!grin_is_vertex_list_end(g, vli)) {
965968
GRIN_VERTEX v = grin_get_vertex_from_iter(g, vli);
966969
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);
969-
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);
970+
for (size_t i = 0; i <= etl_size; ++i) {
971+
GRIN_ADJACENT_LIST al1 = al;
972+
if (i < etl_size) {
973+
GRIN_EDGE_TYPE et = grin_get_edge_type_from_list(g, etl, i);
974+
al1 = grin_select_edge_type_for_adjacent_list(g, et, al);
975+
grin_destroy_edge_type(g, et);
976+
}
977+
978+
GRIN_ADJACENT_LIST_ITERATOR ali = grin_get_adjacent_list_begin(g, al1);
979+
grin_destroy_adjacent_list(g, al1);
980+
981+
size_t cnt = 0;
982+
while (!grin_is_adjacent_list_end(g, ali)) {
983+
cnt++;
984+
GRIN_EDGE e = grin_get_edge_from_adjacent_list_iter(g, ali);
985+
GRIN_VERTEX v1 = grin_get_src_vertex_from_edge(g, e);
986+
GRIN_VERTEX v2 = grin_get_dst_vertex_from_edge(g, e);
987+
GRIN_VERTEX u = grin_get_neighbor_from_adjacent_list_iter(g, ali);
988+
989+
if (dir == OUT) {
990+
if (!grin_equal_vertex(g, v, v1)) {
991+
printf("vertex not match\n");
992+
}
993+
if (!grin_equal_vertex(g, v2, u)) {
994+
printf("vertex not match\n");
995+
}
996+
} else {
997+
if (!grin_equal_vertex(g, v, v2)) {
998+
printf("vertex not match\n");
999+
}
1000+
if (!grin_equal_vertex(g, v1, u)) {
1001+
printf("vertex not match\n");
1002+
}
1003+
}
9771004

1005+
grin_destroy_vertex(g, v1);
1006+
grin_destroy_vertex(g, v2);
1007+
grin_destroy_vertex(g, u);
1008+
grin_destroy_edge(g, e);
1009+
grin_get_next_adjacent_list_iter(g, ali);
1010+
}
1011+
#ifdef GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_INT64
1012+
long long int vid = grin_get_vertex_original_id_of_int64(g, v);
9781013
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");
1014+
if (i < etl_size) {
1015+
printf("vertex %lld OUT adjacent list, edgetype: %zu checked num: %zu\n", vid, i, cnt);
1016+
} else {
1017+
printf("vertex %lld OUT adjacent list, edgetype: all checked num: %zu\n", vid, cnt);
9841018
}
9851019
} 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");
1020+
if (i < etl_size) {
1021+
printf("vertex %lld IN adjacent list, edgetype: %zu checked num: %zu\n", vid, i, cnt);
1022+
} else {
1023+
printf("vertex %lld IN adjacent list, edgetype: all checked num: %zu\n", vid, cnt);
9911024
}
9921025
}
993-
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-
}
10071026
#endif
10081027

1009-
grin_destroy_adjacent_list_iter(g, ali);
1028+
grin_destroy_adjacent_list_iter(g, ali);
1029+
}
10101030
grin_destroy_vertex(g, v);
10111031
grin_get_next_vertex_list_iter(g, vli);
10121032
}

modules/graph/grin/src/predefine.cc

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,8 @@ 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-
if (sum == 0) {
121-
vl->type_begin++;
122-
} else {
123-
vl->offsets.push_back(sum);
124-
vl->vrs.push_back(vr);
125-
}
120+
vl->offsets.push_back(sum);
121+
vl->vrs.push_back(vr);
126122
}
127123
}
128124
#endif
@@ -140,13 +136,9 @@ void __grin_init_adjacent_list(_GRIN_GRAPH_T* g, GRIN_ADJACENT_LIST_T* al) {
140136
} else {
141137
ral = g->GetOutgoingRawAdjList(_GRIN_GRAPH_T::vertex_t(al->vid), etype);
142138
}
143-
sum += ral.size();
144-
if (sum == 0) {
145-
al->etype_begin++;
146-
} else {
147-
al->offsets.push_back(sum);
148-
al->data.push_back(ral);
149-
}
139+
sum += ral.size();
140+
al->offsets.push_back(sum);
141+
al->data.push_back(ral);
150142
}
151143
}
152144
#endif

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +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+
94+
while (ali->etype_current < ali->etype_end) {
95+
if (_al->offsets[ali->etype_current - ali->etype_begin + 1] > 0) break;
96+
ali->etype_current++;
97+
}
98+
9399
if (ali->etype_current < ali->etype_end) {
94100
if (ali->dir == GRIN_DIRECTION::IN) {
95101
ali->data = _g->GetIncomingRawAdjList(_GRIN_GRAPH_T::vertex_t(ali->vid), ali->etype_current);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ 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+
65+
while (vli->type_current < vli->type_end) {
66+
if (_vl->offsets[vli->type_current - vli->type_begin + 1] > 0) break;
67+
vli->type_current++;
68+
}
69+
6470
if (vli->type_current < vli->type_end) {
6571
if (vli->all_master_mirror == 0) {
6672
vli->vr = _g->Vertices(vli->type_current);

0 commit comments

Comments
 (0)