FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
in_mem_storage.h
1 #ifndef __IN_MEM_STORAGE_H__
2 #define __IN_MEM_STORAGE_H__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of FlashGraph.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 #include <stdlib.h>
23 
24 #include <string>
25 #include <memory>
26 
27 #include "io_interface.h"
28 #include "in_mem_io.h"
29 
30 class in_mem_io;
31 class thread_safe_page;
32 
33 namespace fg
34 {
35 
36 class in_mem_graph
37 {
38  size_t graph_size;
39  safs::NUMA_buffer::ptr graph_data;
40  int graph_file_id;
41  std::string graph_file_name;
42 
43  in_mem_graph() {
44  graph_size = 0;
45  graph_file_id = -1;
46  }
47 public:
48  typedef std::shared_ptr<in_mem_graph> ptr;
49 
50  static ptr create(const std::string &graph_name, std::shared_ptr<char> buf,
51  size_t size);
52  /*
53  * in_mem_graph takes the memory buffer and is responsible to free it
54  * afterwards.
55  */
56  static ptr create(const std::string &graph_name, safs::NUMA_buffer::ptr buf,
57  size_t size) {
58  in_mem_graph *g = new in_mem_graph();
59  assert(buf->get_length() >= size);
60  g->graph_size = size;
61  g->graph_data = buf;
62  // TODO we don't init graph_file_id here.
63  g->graph_file_name = graph_name;
64  return ptr(g);
65  }
66 
67  static ptr load_graph(const std::string &graph_file);
68  static ptr load_safs_graph(const std::string &graph_file);
69 
70  void dump(const std::string &file) const;
71 
72  std::shared_ptr<safs::file_io_factory> create_io_factory() const;
73 };
74 
75 }
76 
77 #endif
file_io_factory::shared_ptr create_io_factory(const std::string &file_name, const int access_option)