Skip to content

Commit d3a44f4

Browse files
committed
optimize vertexlist and adjlist impl
1 parent 9148ed7 commit d3a44f4

File tree

10 files changed

+355
-383
lines changed

10 files changed

+355
-383
lines changed

modules/graph/grin/src/index/order.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ bool grin_smaller_vertex(GRIN_GRAPH g, GRIN_VERTEX v1, GRIN_VERTEX v2) {
2424

2525
#if defined(GRIN_ASSUME_ALL_VERTEX_LIST_SORTED) && defined(GRIN_ENABLE_VERTEX_LIST_ARRAY)
2626
size_t grin_get_position_of_vertex_from_sorted_list(GRIN_GRAPH g, GRIN_VERTEX_LIST vl, GRIN_VERTEX v) {
27-
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
2827
auto _vl = static_cast<GRIN_VERTEX_LIST_T*>(vl);
29-
auto bg = static_cast<GRIN_GRAPH_T*>(g);
30-
auto vtype = bg->cache->id_parser.GetLabelId(v);
31-
if (vtype < _vl->type_begin || vtype >= _vl->type_end) return GRIN_NULL_SIZE;
32-
auto offset = v - _vl->vrs[vtype - _vl->type_begin].begin_value();
33-
if (offset < _vl->vrs[vtype - _vl->type_begin].size()) {
34-
return _vl->offsets[vtype - _vl->type_begin] + offset;
35-
}
36-
return GRIN_NULL_SIZE;
28+
if (v < _vl->end_ && v >= _vl->begin_) return v - _vl->begin_;
29+
if (_vl->is_simple) return GRIN_NULL_SIZE;
30+
if (_vl->offsets.empty()) __grin_init_complex_vertex_list(static_cast<GRIN_GRAPH_T*>(g)->g, _vl);
31+
auto _cache = static_cast<GRIN_GRAPH_T*>(g)->cache;
32+
auto vtype = _cache->id_parser.GetLabelId(v);
33+
return v - _vl->offsets[vtype].second + _vl->offsets[vtype].first;
3734
}
3835
#endif

modules/graph/grin/src/partition/reference.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ GRIN_VERTEX grin_get_vertex_from_vertex_ref(GRIN_GRAPH g, GRIN_VERTEX_REF vr) {
3636
}
3737

3838
GRIN_PARTITION grin_get_master_partition_from_vertex_ref(GRIN_GRAPH g, GRIN_VERTEX_REF vr) {
39-
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
40-
auto bg = static_cast<GRIN_GRAPH_T*>(g);
41-
return bg->cache->id_parser.GetFid(vr);
39+
auto _cache = static_cast<GRIN_GRAPH_T*>(g)->cache;
40+
return _cache->id_parser.GetFid(vr);
4241
}
4342

4443
const char* grin_serialize_vertex_ref(GRIN_GRAPH g, GRIN_VERTEX_REF vr) {

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,26 @@ extern "C" {
2020

2121
#ifdef GRIN_TRAIT_SELECT_MASTER_FOR_VERTEX_LIST
2222
GRIN_VERTEX_LIST grin_select_master_for_vertex_list(GRIN_GRAPH g, GRIN_VERTEX_LIST vl) {
23-
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
2423
auto _vl = static_cast<GRIN_VERTEX_LIST_T*>(vl);
2524
if (_vl->all_master_mirror > 0) return GRIN_NULL_LIST;
26-
25+
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
2726
auto fvl = new GRIN_VERTEX_LIST_T();
28-
fvl->type_begin = _vl->type_begin;
29-
fvl->type_end = _vl->type_end;
3027
fvl->all_master_mirror = 1;
31-
__grin_init_vertex_list(_g, fvl);
28+
fvl->vtype = _vl->vtype;
29+
fvl->is_simple = _vl->is_simple;
30+
if (fvl->is_simple) __grin_init_simple_vertex_list(_g, fvl);
3231
return fvl;
3332
}
3433

3534
GRIN_VERTEX_LIST grin_select_mirror_for_vertex_list(GRIN_GRAPH g, GRIN_VERTEX_LIST vl) {
36-
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
3735
auto _vl = static_cast<GRIN_VERTEX_LIST_T*>(vl);
3836
if (_vl->all_master_mirror > 0) return GRIN_NULL_LIST;
39-
37+
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
4038
auto fvl = new GRIN_VERTEX_LIST_T();
41-
fvl->type_begin = _vl->type_begin;
42-
fvl->type_end = _vl->type_end;
4339
fvl->all_master_mirror = 2;
44-
__grin_init_vertex_list(_g, fvl);
40+
fvl->vtype = _vl->vtype;
41+
fvl->is_simple = _vl->is_simple;
42+
if (fvl->is_simple) __grin_init_simple_vertex_list(_g, fvl);
4543
return fvl;
4644
}
4745
#endif

modules/graph/grin/src/predefine.cc

Lines changed: 0 additions & 189 deletions
This file was deleted.

0 commit comments

Comments
 (0)