30 #ifndef DEF_GRAPHCHI_OBJECTS
31 #define DEF_GRAPHCHI_OBJECTS
38 #include "graphchi_types.hpp"
39 #include "util/qsort.hpp"
48 #define VARIABLE_IS_NOT_USED __attribute__ ((unused))
50 #define VARIABLE_IS_NOT_USED
53 template <
typename EdgeDataType>
58 EdgeDataType * data_ptr;
61 graphchi_edge(vid_t _vertexid, EdgeDataType * edata_ptr) : vertexid(_vertexid), data_ptr(edata_ptr) {
65 EdgeDataType get_data() {
69 void set_data(EdgeDataType x) {
83 template <
typename ET>
84 bool eptr_less(
const graphchi_edge<ET> &a,
const graphchi_edge<ET> &b) {
85 return a.vertexid < b.vertexid;
89 template <
typename VertexDataType,
typename EdgeDataType>
112 #ifdef SUPPORT_DELETIONS
119 #ifdef SUPPORT_DELETIONS
120 deleted_outc = deleted_inc = 0;
130 vertexid(_id), inedges_ptr(iptr), outedges_ptr(optr) {
135 parallel_safe =
true;
137 #ifdef SUPPORT_DELETIONS
150 int num_inedges()
const {
154 int num_outedges()
const {
157 int num_edges()
const {
164 inline void add_inedge(vid_t src, EdgeDataType * ptr,
bool special_edge) {
165 #ifdef SUPPORT_DELETIONS
166 if (inedges_ptr != NULL && is_deleted_edge_value(*ptr)) {
174 assert(src != vertexid);
177 inline void add_outedge(vid_t dst, EdgeDataType * ptr,
bool special_edge) {
178 #ifdef SUPPORT_DELETIONS
179 if (outedges_ptr != NULL && is_deleted_edge_value(*ptr)) {
184 int i = __sync_add_and_fetch(&outc, 1);
186 assert(dst != vertexid);
192 template <
typename VertexDataType,
typename EdgeDataType >
213 if (i < this->inc)
return inedge(i);
214 else return outedge(i - this->inc);
219 assert(i >= 0 && i < this->inc);
220 return &this->inedges_ptr[i];
223 graphchi_edge<EdgeDataType> * outedge(
int i) {
224 assert(i >= 0 && i < this->outc);
225 return &this->outedges_ptr[i];
234 return *(this->dataptr);
242 *(this->dataptr) = d;
243 this->modified =
true;
247 static bool computational_edges() {
250 static bool read_outedges() {
262 if (this->inc != (this->outedges_ptr - this->inedges_ptr)) {
265 this->outedges_ptr = &this->inedges_ptr[this->inc];
267 quickSort(this->inedges_ptr, (
int) (this->inc + this->outc), eptr_less<EdgeDataType>);
272 #ifdef SUPPORT_DELETIONS
274 remove_edgev(
edge(i));
278 remove_edgev(inedge(i));
282 remove_edgev(outedge(i));
296 #define HIGHMASK (1 + (2147483647 >> 1))
297 #define CLEARMASK (2147483647 >> 1)
298 inline vid_t translate_edge(vid_t rawid,
bool &is_special) {
299 is_special = (rawid &
HIGHMASK) != 0;
300 return rawid & CLEARMASK;
302 inline vid_t make_special(vid_t rawid) {
305 inline bool is_special(vid_t rawid) {
309 #ifdef SUPPORT_DELETIONS
324 return 0xffffffff == (
unsigned int)val;
328 return 0xffffffffu == val;
333 return !(val < 0 || val > 0);
343 e->set_data(0xffffffff);
348 e->set_data(0xffffffff);