GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dynamic_graph_storage.hpp
1 /**
2  * Copyright (c) 2011 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 /* *
24  * Author: Haijie Gu ([email protected])
25  * Date: 11/10/2011
26  *
27  * CSR+CSC implementation of a graph storage.
28  * */
29 
30 #ifndef GRAPHLAB_GRAPH_STORAGE_HPP
31 #define GRAPHLAB_GRAPH_STORAGE_HPP
32 
33 
34 #ifndef __NO_OPENMP__
35 #include <omp.h>
36 #endif
37 
38 
39 #include <cmath>
40 
41 #include <string>
42 #include <list>
43 #include <vector>
44 #include <set>
45 #include <map>
46 
47 #include <queue>
48 #include <algorithm>
49 #include <functional>
50 #include <fstream>
51 
52 #include <boost/version.hpp>
53 #include <boost/bind.hpp>
54 #include <boost/unordered_set.hpp>
55 #include <boost/iterator.hpp>
56 #include <boost/iterator/counting_iterator.hpp>
57 #include <boost/iterator/iterator_facade.hpp>
58 
60 #include <graphlab/logger/assertions.hpp>
61 
62 #include <graphlab/serialization/iarchive.hpp>
63 #include <graphlab/serialization/oarchive.hpp>
64 
65 #include <graphlab/util/random.hpp>
66 #include <graphlab/util/generics/shuffle.hpp>
67 #include <graphlab/graph/graph_basic_types.hpp>
68 
69 
70 #include <graphlab/parallel/atomic.hpp>
71 
72 #include <graphlab/macros_def.hpp>
73 
74 namespace graphlab {
75 
76 
77 
78 
79 
80 
81  template<typename VertexData, typename EdgeData>
82  class graph_storage {
83  public:
86 
87  /** The type of the edge data stored in the graph. */
88  typedef EdgeData edge_data_type;
89 
90  /** The type of the vertex data stored in the graph. */
91  typedef VertexData vertex_data_type;
92 
93 
94  public:
95 
96 
97  // A class of edge information. Used as value type of the edge_list.
98  class edge_type {
99  public:
100  /** \brief Creates an empty edge type. */
101  edge_type () : _source(-1), _target(-1), _edge_id(-1),
102  _dir(NO_EDGES), _empty(true) { }
103  /** \brief Creates an edge of given source id, target id, edge
104  * id and direction enum. \internal edge id is used to locate
105  * the edge data in the edge_data array. edge_dir type is
106  * defined in graph_basic.hpp. **/
107  edge_type (const lvid_type _source,
108  const lvid_type _target,
109  const edge_id_type _eid, edge_dir_type _dir) :
110  _source(_source), _target(_target), _edge_id(_eid),
111  _dir(_dir), _empty(false) {
112  }
113  public:
114  /** \brief Returns the source vertex id of the edge. */
115  inline lvid_type source() const {
116  return _source;
117  }
118  /** \brief Returns the target vertex id of the edge. */
119  inline lvid_type target() const {
120  return _target;
121  }
122  /** \brief Returns the direction of the edge. */
123  inline edge_dir_type get_dir() const {
124  return _dir;
125  }
126  /** \brief Returns whether this is an empty edge. */
127  inline bool empty() const { return _empty; }
128  // Data fields.
129  private:
130  lvid_type _source;
131  lvid_type _target;
132  edge_id_type _edge_id;
133  edge_dir_type _dir;
134  bool _empty;
135 
136  friend class graph_storage;
137  }; // end of class edge_type.
138 
139  // Internal iterator on edge_types.
140  class edge_iterator {
141  public:
142  typedef std::random_access_iterator_tag iterator_category;
143  typedef edge_type value_type;
144  typedef ssize_t difference_type;
145  typedef edge_type* pointer;
146  typedef edge_type reference;
147 
148  public:
149  // Cosntructors
150  /** \brief Creates an empty iterator. */
151  edge_iterator () : offset(-1), empty(true) { }
152 
153  edge_iterator (lvid_type _center, size_t _offset,
154  edge_dir_type _itype, const edge_id_type* _vid_arr) :
155  center(_center), offset(_offset), itype(_itype), vid_arr(_vid_arr),
156  empty(false) { }
157 
158  /** \brief Returns the value of the iterator. An empty iterator always returns empty edge type*/
159  inline edge_type operator*() const {
160  }
161 
162  inline typename arrow_type::type operator->() const {
163  return arrow_type::make(make_value());
164  }
165 
166  operator_arrow_dispatch<edge_type, edge_type*>::result_type arrow_type;
167  inline arrow_type operator->() const {
168  return arrow_type(make_value());
169  }
170  /** \brief Returns if two iterators point to the same edge. */
171  inline bool operator==(const edge_iterator& it) const {
172  }
173 
174  /** \brief Returns if two iterators don't point to the same edge. */
175  inline bool operator!=(const edge_iterator& it) const {
176  return !(*this == it);
177  }
178 
179  /** \brief Increases the iterator. */
180  inline edge_iterator& operator++() {
181  }
182 
183  /** \brief Increases the iterator. */
184  inline edge_iterator operator++(int) {
185  }
186 
187  /** \brief Computes the difference of two iterators. */
188  inline ssize_t operator-(const edge_iterator& it) const {
189  }
190 
191  /** \brief Returns a new iterator whose value is increased by i difference units. */
192  inline edge_iterator operator+(difference_type i) const {
193  }
194 
195  /** \brief Increases the iterator by i difference units. */
196  inline edge_iterator& operator+=(difference_type i) {
197  return *this;
198  }
199 
200  /** \brief Generate the return value of the iterator. */
201  inline edge_type make_value() const {
202  }
203 
204  private:
205  }; // end of class edge_iterator.
206 
207  /** Represents an iteratable list of edge_types. */
208  class edge_list {
209  public:
210  typedef edge_iterator iterator;
211  typedef edge_iterator const_iterator;
212  typedef edge_type value_type;
213  private:
214  edge_iterator begin_iter, end_iter;
215  public:
216  /** Cosntructs an edge_list with begin and end. */
217  edge_list(const edge_iterator begin_iter = edge_iterator(),
218  const edge_iterator end_iter = edge_iterator()) :
219  begin_iter(begin_iter), end_iter(end_iter) { }
220  inline size_t size() const { return end_iter - begin_iter;}
221  inline edge_type operator[](size_t i) const {return *(begin_iter + i);}
222  iterator begin() const { return begin_iter; }
223  iterator end() const { return end_iter; }
224  bool empty() const { return size() == 0; }
225  }; // end of class edge_list.
226 
227 
228  public:
229  // CONSTRUCTORS ============================================================>
230  graph_storage() : use_skip_list(false) { }
231 
232  // METHODS =================================================================>
233 
234 
235  /** \brief Returns the number of edges in the graph. */
236  size_t edge_size() const { return num_edges; }
237 
238  /** \brief Returns the number of vertices in the graph. */
239  size_t vertices_size() const { return num_vertices; }
240 
241  /** \brief Returns the number of in edges of the vertex. */
242  size_t num_in_edges (const lvid_type v) const {
243  }
244 
245  /** \brief Returns the number of out edges of the vertex. */
246  size_t num_out_edges (const lvid_type v) const {
247  }
248 
249  /** \brief Returns the edge id of the edge.
250  * Edges are assigned with consecutive int ids,
251  * ordered first by source and then by target.
252  * */
253  edge_id_type edge_id(const edge_type& edge) const {
254  }
255 
256  /** \brief Returns the reference of edge data of an edge. */
257  edge_data_type& edge_data(lvid_type source, lvid_type target) {
258  }
259 
260  /** \brief Returns the constant reference of edge data of an edge. */
261  const edge_data_type& edge_data(lvid_type source,
262  lvid_type target) const {
263  }
264 
265  /** \brief Returns the reference of edge data of an edge. */
266  edge_data_type& edge_data(edge_type edge) {
267  }
268 
269  /** \brief Returns the constant reference of edge data of an edge. */
270  const edge_data_type& edge_data(edge_type edge) const {
271  }
272 
273  /** \brief Returns a list of in edges of a vertex. */
274  edge_list in_edges(const lvid_type v) const {
275  }
276 
277  /** \brief Returns a list of out edges of a vertex. */
278  edge_list out_edges(const lvid_type v) const {
279  }
280 
281  /** \brief Returns an edge type of a given source target pair. */
282  edge_type find (const lvid_type src,
283  const lvid_type dst) const {
284  } // end of find.
285 
286  /** \brief Finalize the graph storage.
287  */
288  void finalize(size_t _num_of_v, edge_info &edges){
289  } // end of finalize.
290 
291  /** \brief Reset the storage. */
292  void clear() {
293  }
294 
295 
296  // ------------- Private data storage ----------------
297  private:
298  /** Number of vertices in the storage (not counting singletons)*/
299  size_t num_vertices;
300  /** Number of edges in the storage. */
301  size_t num_edges;
302 
303  struct row {
304  };
305 
306  std::vector<std::vector> CSC_dst;
307 
308 
309 
310  public:
311  /** \brief Load the graph from an archive */
312  void load(iarchive& arc) {
313  clear();
314  }
315 
316  /** \brief Save the graph to an archive */
317  void save(oarchive& arc) const {
318  }
319 
320  /** swap two graph storage*/
321  void swap(graph_storage& other) {
322  }
323 
324  };// End of graph store;
325 }// End of namespace;
326 
327 #include <graphlab/macros_undef.hpp>
328 #endif