Skip to content

Commit 7dd3cf5

Browse files
committed
change vertex handler from void* to int64
1 parent 3c0367c commit 7dd3cf5

File tree

16 files changed

+67
-100
lines changed

16 files changed

+67
-100
lines changed

modules/graph/grin/predefine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ typedef enum {
825825
/** @brief Null graph (invalid return value) */
826826
#define GRIN_NULL_GRAPH NULL
827827
/** @brief Non-existing vertex (invalid return value) */
828-
#define GRIN_NULL_VERTEX NULL
828+
#define GRIN_NULL_VERTEX (unsigned long long int)~0
829829
/** @brief Non-existing edge (invalid return value) */
830830
#define GRIN_NULL_EDGE NULL
831831
/** @brief Null list of any kind (invalid return value) */
@@ -859,7 +859,7 @@ typedef enum {
859859

860860
/* Define the handlers using typedef */
861861
typedef void* GRIN_GRAPH;
862-
typedef void* GRIN_VERTEX;
862+
typedef unsigned long long int GRIN_VERTEX;
863863
typedef void* GRIN_EDGE;
864864

865865
#ifdef GRIN_WITH_VERTEX_DATA

modules/graph/grin/rust/v6d_all.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/// RUST_KEEP pub const GRIN_NULL_DATATYPE: GrinDatatype = GRIN_DATATYPE_UNDEFINED;
2121
/// RUST_KEEP pub const GRIN_NULL_GRAPH: GrinGraph = std::ptr::null_mut();
22-
/// RUST_KEEP pub const GRIN_NULL_VERTEX: GrinVertex = std::ptr::null_mut();
22+
/// RUST_KEEP pub const GRIN_NULL_VERTEX: GrinVertex = u64::MAX;
2323
/// RUST_KEEP pub const GRIN_NULL_EDGE: GrinEdge = std::ptr::null_mut();
2424
/// RUST_KEEP pub const GRIN_NULL_LIST: *mut ::std::os::raw::c_void = std::ptr::null_mut();
2525
/// RUST_KEEP pub const GRIN_NULL_LIST_ITERATOR: *mut ::std::os::raw::c_void = std::ptr::null_mut();

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,20 @@ extern "C" {
1818

1919
#ifdef GRIN_ASSUME_ALL_VERTEX_LIST_SORTED
2020
bool grin_smaller_vertex(GRIN_GRAPH g, GRIN_VERTEX v1, GRIN_VERTEX v2) {
21-
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
22-
auto _v1 = static_cast<GRIN_VERTEX_T*>(v1);
23-
auto _v2 = static_cast<GRIN_VERTEX_T*>(v2);
24-
return _g->Vertex2Gid(*_v1) < _g->Vertex2Gid(*_v2);
21+
return v1 < v2;
2522
}
2623
#endif
2724

2825
#if defined(GRIN_ASSUME_ALL_VERTEX_LIST_SORTED) && defined(GRIN_ENABLE_VERTEX_LIST_ARRAY)
2926
size_t grin_get_position_of_vertex_from_sorted_list(GRIN_GRAPH g, GRIN_VERTEX_LIST vl, GRIN_VERTEX v) {
3027
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
31-
auto _v = static_cast<GRIN_VERTEX_T*>(v);
3228
auto _vl = static_cast<GRIN_VERTEX_LIST_T*>(vl);
33-
return _v->GetValue() - _vl->vrs[0].begin_value();
34-
// auto vtype = (unsigned)_g->vertex_label(*_v);
35-
// if (vtype < _vl->type_begin || vtype >= _vl->type_end) return GRIN_NULL_SIZE;
36-
// auto offset = _v->GetValue() - _vl->vrs[vtype - _vl->type_begin].begin_value();
37-
// if (offset < _vl->vrs[vtype - _vl->type_begin].size()) {
38-
// return _vl->offsets[vtype - _vl->type_begin] + offset;
39-
// }
40-
// return GRIN_NULL_SIZE;
29+
auto vtype = (unsigned)_g->vertex_label(_GRIN_VERTEX_T(v)); // TODO: optimize after rebase
30+
if (vtype < _vl->type_begin || vtype >= _vl->type_end) return GRIN_NULL_SIZE;
31+
auto offset = v - _vl->vrs[vtype - _vl->type_begin].begin_value();
32+
if (offset < _vl->vrs[vtype - _vl->type_begin].size()) {
33+
return _vl->offsets[vtype - _vl->type_begin] + offset;
34+
}
35+
return GRIN_NULL_SIZE;
4136
}
4237
#endif

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ GRIN_DATATYPE grin_get_vertex_original_id_datatype(GRIN_GRAPH g) {
2323
#ifdef GRIN_ENABLE_VERTEX_ORIGINAL_ID_OF_INT64
2424
long long int grin_get_vertex_original_id_of_int64(GRIN_GRAPH g, GRIN_VERTEX v) {
2525
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
26-
auto _v = static_cast<GRIN_VERTEX_T*>(v);
27-
auto gid = _g->Vertex2Gid(*_v);
26+
auto gid = _g->Vertex2Gid(_GRIN_VERTEX_T(v));
2827
return _g->Gid2Oid(gid);
2928
}
3029

3130
GRIN_VERTEX grin_get_vertex_by_original_id_of_int64(GRIN_GRAPH g, long long int oid) {
3231
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
3332
_GRIN_GRAPH_T::vid_t gid;
34-
auto v = new GRIN_VERTEX_T();
33+
_GRIN_VERTEX_T v;
3534
if (_g->Oid2Gid(0, oid, gid)) {
36-
if (_g->Gid2Vertex(gid, *v)) {
37-
return v;
35+
if (_g->Gid2Vertex(gid, v)) {
36+
return v.GetValue();
3837
}
3938
}
4039
return GRIN_NULL_VERTEX;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ GRIN_PARTITIONED_GRAPH grin_get_partitioned_graph_from_storage(int argc, char**
3535
for (auto & [fid, location] : pg->pg->FragmentLocations()) {
3636
if (location == pg->client.instance_id()) {
3737
auto obj_id = pg->pg->Fragments().at(fid);
38-
// std::cout << fid << ": " << obj_id << std::endl;
39-
// auto frag = std::dynamic_pointer_cast<_GRIN_GRAPH_T>(pg->client.GetObject(obj_id));
4038
pg->lgs[fid] = obj_id;
4139
}
4240
}
43-
return pg;
41+
return pg;
4442
}
4543

4644
void grin_destroy_partitioned_graph(GRIN_PARTITIONED_GRAPH pg) {

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,23 @@ extern "C" {
2121
#ifdef GRIN_ENABLE_VERTEX_REF
2222
GRIN_VERTEX_REF grin_get_vertex_ref_by_vertex(GRIN_GRAPH g, GRIN_VERTEX v) {
2323
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
24-
auto _v = static_cast<GRIN_VERTEX_T*>(v);
25-
return _g->Vertex2Gid(*_v);
24+
return _g->Vertex2Gid(_GRIN_VERTEX_T(v));
2625
}
2726

2827
void grin_destroy_vertex_ref(GRIN_GRAPH g, GRIN_VERTEX_REF vr) {}
2928

3029
GRIN_VERTEX grin_get_vertex_from_vertex_ref(GRIN_GRAPH g, GRIN_VERTEX_REF vr) {
3130
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
32-
auto v = new GRIN_VERTEX_T();
33-
if (_g->Gid2Vertex(vr, *v)) {
34-
return v;
31+
_GRIN_VERTEX_T v;
32+
if (_g->Gid2Vertex(vr, v)) {
33+
return v.GetValue();
3534
}
3635
return GRIN_NULL_VERTEX;
3736
}
3837

3938
GRIN_PARTITION grin_get_master_partition_from_vertex_ref(GRIN_GRAPH g, GRIN_VERTEX_REF vr) {
4039
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
41-
auto id_parser = vineyard::IdParser<GRIN_VERTEX_REF_T>();
40+
auto id_parser = vineyard::IdParser<GRIN_VERTEX_REF_T>(); //TODO optimize after rebase
4241
id_parser.Init(_g->fnum(), _g->vertex_label_num());
4342
return id_parser.GetFid(vr);
4443
}
@@ -75,14 +74,12 @@ GRIN_VERTEX_REF grin_deserialize_to_vertex_ref(GRIN_GRAPH g, const char* msg) {
7574

7675
bool grin_is_master_vertex(GRIN_GRAPH g, GRIN_VERTEX v) {
7776
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
78-
auto _v = static_cast<GRIN_VERTEX_T*>(v);
79-
return _g->IsInnerVertex(*_v);
77+
return _g->IsInnerVertex(_GRIN_VERTEX_T(v)); // TODO
8078
}
8179

8280
bool grin_is_mirror_vertex(GRIN_GRAPH g, GRIN_VERTEX v) {
8381
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
84-
auto _v = static_cast<GRIN_VERTEX_T*>(v);
85-
return _g->IsOuterVertex(*_v);
82+
return _g->IsOuterVertex(_GRIN_VERTEX_T(v)); // TODO
8683
}
8784
#endif
8885

modules/graph/grin/src/predefine.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ const void* _get_value_from_vertex_property_table(GRIN_GRAPH g, GRIN_VERTEX_PROP
7272
grin_error_code = GRIN_ERROR_CODE::NO_ERROR;
7373
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
7474
auto _vpt = static_cast<GRIN_VERTEX_PROPERTY_TABLE_T*>(vpt);
75-
auto _v = static_cast<GRIN_VERTEX_T*>(v);
76-
unsigned vtype = _grin_get_type_from_property(vp);
77-
unsigned vprop = _grin_get_prop_from_property(vp);
78-
if (vtype != _vpt->vtype || !_vpt->vertices.Contain(*_v)) {
75+
if (v < _vpt->vbegin || v >= _vpt->vend) {
7976
grin_error_code = GRIN_ERROR_CODE::INVALID_VALUE;
8077
return NULL;
8178
}
82-
auto offset = _v->GetValue() - _vpt->vertices.begin_value();
79+
unsigned vtype = _grin_get_type_from_property(vp);
80+
unsigned vprop = _grin_get_prop_from_property(vp);
81+
auto offset = v - _vpt->vbegin;
8382
auto array = _g->vertex_data_table(vtype)->column(vprop)->chunk(0);
8483
return vineyard::get_arrow_array_data_element(array, offset);
8584
}
@@ -107,7 +106,7 @@ void __grin_init_vertex_list(_GRIN_GRAPH_T* g, GRIN_VERTEX_LIST_T* vl) {
107106
vl->vrs.clear();
108107
_GRIN_GRAPH_T::vertices_t vr;
109108
vl->offsets.push_back(0);
110-
unsigned sum = 0;
109+
size_t sum = 0;
111110
for (auto vtype = vl->type_begin; vtype < vl->type_end; ++vtype) {
112111
if (vl->all_master_mirror == 0) {
113112
vr = g->Vertices(vtype);
@@ -129,7 +128,7 @@ void __grin_init_adjacent_list(_GRIN_GRAPH_T* g, GRIN_ADJACENT_LIST_T* al) {
129128
al->data.clear();
130129
_GRIN_GRAPH_T::raw_adj_list_t ral;
131130
al->offsets.push_back(0);
132-
unsigned sum = 0;
131+
size_t sum = 0;
133132
for (auto etype = al->etype_begin; etype < al->etype_end; ++etype) {
134133
if (al->dir == GRIN_DIRECTION::IN) {
135134
ral = g->GetIncomingRawAdjList(_GRIN_GRAPH_T::vertex_t(al->vid), etype);

modules/graph/grin/src/predefine.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct GRIN_GRAPH_T {
102102
std::shared_ptr<_GRIN_GRAPH_T> _g;
103103
_GRIN_GRAPH_T* g;
104104
};
105-
typedef _GRIN_GRAPH_T::vertex_t GRIN_VERTEX_T;
105+
typedef _GRIN_GRAPH_T::vertex_t _GRIN_VERTEX_T;
106106
struct GRIN_EDGE_T {
107107
_GRIN_GRAPH_T::vid_t src;
108108
_GRIN_GRAPH_T::vid_t dst;
@@ -116,7 +116,7 @@ struct GRIN_VERTEX_LIST_T {
116116
unsigned type_begin;
117117
unsigned type_end;
118118
unsigned all_master_mirror;
119-
std::vector<unsigned> offsets;
119+
std::vector<size_t> offsets;
120120
std::vector<_GRIN_GRAPH_T::vertices_t> vrs;
121121
};
122122
void __grin_init_vertex_list(_GRIN_GRAPH_T* g, GRIN_VERTEX_LIST_T* vl);
@@ -139,7 +139,7 @@ struct GRIN_ADJACENT_LIST_T {
139139
GRIN_DIRECTION dir;
140140
unsigned etype_begin;
141141
unsigned etype_end;
142-
std::vector<unsigned> offsets;
142+
std::vector<size_t> offsets;
143143
std::vector<_GRIN_GRAPH_T::raw_adj_list_t> data;
144144
};
145145
void __grin_init_adjacent_list(_GRIN_GRAPH_T* g, GRIN_ADJACENT_LIST_T* al);
@@ -179,7 +179,8 @@ typedef unsigned long long int GRIN_VERTEX_PROPERTY_T;
179179
typedef std::vector<GRIN_VERTEX_PROPERTY_T> GRIN_VERTEX_PROPERTY_LIST_T;
180180
struct GRIN_VERTEX_PROPERTY_TABLE_T {
181181
unsigned vtype;
182-
_GRIN_GRAPH_T::vertices_t vertices;
182+
_GRIN_GRAPH_T::vid_t vbegin;
183+
_GRIN_GRAPH_T::vid_t vend;
183184
};
184185
#endif
185186

modules/graph/grin/src/property/primarykey.cc

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,26 @@ GRIN_VERTEX grin_get_vertex_by_primary_keys(GRIN_GRAPH g, GRIN_VERTEX_TYPE vtype
5656
auto _g = static_cast<GRIN_GRAPH_T*>(g)->g;
5757
auto _r = static_cast<GRIN_ROW_T*>(r);
5858
auto value = (*_r)[0];
59+
#if 0
5960
for (auto p = 0; p < _g->vertex_property_num(vtype); ++p) {
6061
if (_g->schema().GetVertexPropertyName(vtype, p) == "id") {
6162
auto arrow_dt = _g->schema().GetVertexPropertyType(vtype, p);
6263
auto dt = ArrowToDataType(arrow_dt);
6364

64-
if (dt == GRIN_DATATYPE::Int32) {
65-
auto vid = static_cast<const int32_t*>(value);
66-
auto _v = new GRIN_VERTEX_T();
67-
if (!_g->GetVertex(vtype, *vid, *_v)) return GRIN_NULL_VERTEX;
68-
return _v;
69-
} else if (dt == GRIN_DATATYPE::UInt32) {
70-
auto vid = static_cast<const uint32_t*>(value);
71-
auto _v = new GRIN_VERTEX_T();
72-
if (!_g->GetVertex(vtype, *vid, *_v)) return GRIN_NULL_VERTEX;
73-
return _v;
74-
} else if (dt == GRIN_DATATYPE::Int64) {
65+
if (dt == GRIN_DATATYPE::Int64) {
66+
#endif
67+
_GRIN_VERTEX_T v;
7568
auto vid = static_cast<const int64_t*>(value);
76-
auto _v = new GRIN_VERTEX_T();
77-
if (!_g->GetVertex(vtype, *vid, *_v)) return GRIN_NULL_VERTEX;
78-
return _v;
79-
} else if (dt == GRIN_DATATYPE::UInt64) {
80-
auto vid = static_cast<const uint64_t*>(value);
81-
auto _v = new GRIN_VERTEX_T();
82-
if (!_g->GetVertex(vtype, *vid, *_v)) return GRIN_NULL_VERTEX;
83-
return _v;
69+
if (!_g->GetVertex(vtype, *vid, v)) return GRIN_NULL_VERTEX;
70+
return v.GetValue();
71+
#if 0
72+
} else {
73+
return GRIN_NULL_VERTEX;
8474
}
8575
}
8676
}
8777
return GRIN_NULL_VERTEX;
78+
#endif
8879
}
8980
#endif
9081

0 commit comments

Comments
 (0)