GraphChi  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros
edgebuffers.hpp
Go to the documentation of this file.
1 
29 #ifndef DEF_GRAPHCHI_EDGEBUFFERS
30 #define DEF_GRAPHCHI_EDGEBUFFERS
31 
32 #include <stdlib.h>
33 #include <vector>
34 
35 
36 namespace graphchi {
37 
42  template <typename EdgeDataType>
43  struct created_edge {
44  vid_t src;
45  vid_t dst;
46  EdgeDataType data;
47  bool accounted_for_outc;
48  bool accounted_for_inc;
49  created_edge(vid_t src, vid_t dst, EdgeDataType _data) : src(src), dst(dst), data(_data), accounted_for_outc(false),
50  accounted_for_inc(false) {}
51  };
52 
53 #define EDGE_BUFFER_CHUNKSIZE 65536
54 
59  template <typename ET>
61 
62  unsigned int count;
63  std::vector<created_edge<ET> *> bufs;
64 
65  public:
66 
67  edge_buffer_flat() : count(0) {
68  }
69 
70  ~edge_buffer_flat() {
71  clear();
72  }
73 
74  void clear() {
75  for(int i=0; i< (int)bufs.size(); i++) {
76  free(bufs[i]);
77  }
78  bufs.clear();
79  count = 0;
80  }
81 
82  unsigned int size() {
83  return count;
84  }
85 
86  created_edge<ET> * operator[](unsigned int i) {
87  return &bufs[i / EDGE_BUFFER_CHUNKSIZE][i % EDGE_BUFFER_CHUNKSIZE];
88  }
89 
90  void add(vid_t src, vid_t dst, ET data) {
91  add(created_edge<ET>(src, dst, data));
92  }
93 
94  void add(created_edge<ET> cedge) {
95  int idx = count++;
96  int bufidx = idx / EDGE_BUFFER_CHUNKSIZE;
97  if (bufidx == (int) bufs.size()) {
98  bufs.push_back((created_edge<ET>*)calloc(sizeof(created_edge<ET>), EDGE_BUFFER_CHUNKSIZE));
99  }
100  bufs[bufidx][idx % EDGE_BUFFER_CHUNKSIZE] = cedge;
101  }
102 
103  private:
104  // Disable value copying
106  edge_buffer_flat& operator=(const edge_buffer_flat&);
107  };
108 
109 
110 };
111 
112 #endif