FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
mem_vv_store.h
1 #ifndef __MEM_VV_STORE_H__
2 #define __MEM_VV_STORE_H__
3 
4 /*
5  * Copyright 2015 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of FlashMatrix.
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 
23 #include "vv_store.h"
24 #include "mem_vec_store.h"
25 
26 namespace fm
27 {
28 
29 class local_vv_store;
30 
31 namespace detail
32 {
33 
34 class matrix_store;
35 
36 class mem_vv_store: public vv_store
37 {
38  const smp_vec_store &get_mem_data() const {
39  return static_cast<const smp_vec_store &>(get_data());
40  }
41  smp_vec_store &get_mem_data() {
42  return static_cast<smp_vec_store &>(get_data());
43  }
44 protected:
45  mem_vv_store(const scalar_type &type): vv_store(type, true) {
46  }
47  mem_vv_store(const std::vector<off_t> &offs,
48  mem_vec_store::ptr vec): vv_store(offs, vec) {
49  }
50 public:
51  typedef std::shared_ptr<mem_vv_store> ptr;
52  typedef std::shared_ptr<const mem_vv_store> const_ptr;
53 
54  static ptr cast(vec_store::ptr store);
55 
56  static ptr create(const scalar_type &type) {
57  return ptr(new mem_vv_store(type));
58  }
59 
60  static ptr create(const std::vector<off_t> &offs, const scalar_type &type) {
61  smp_vec_store::ptr vec = smp_vec_store::create(offs.back(), type);
62  return ptr(new mem_vv_store(offs, vec));
63  }
64 
65  static ptr create(const detail::raw_data_array &data,
66  const std::vector<off_t> &offs, const scalar_type &type) {
67  assert(offs.front() == 0 && (size_t) offs.back() == data.get_num_bytes());
68  smp_vec_store::ptr vec = smp_vec_store::create(data, type);
69  return ptr(new mem_vv_store(offs, vec));
70  }
71 
72  virtual void set_data(const set_vv_operate &op);
73 
74  char *get_raw_arr() {
75  return get_mem_data().get_raw_arr();
76  }
77  const char *get_raw_arr() const {
78  return get_mem_data().get_raw_arr();
79  }
80 
81  char*get_raw_arr(off_t idx) {
82  return get_raw_arr() + get_vec_off(idx);
83  }
84 
85  const char*get_raw_arr(off_t idx) const {
86  return get_raw_arr() + get_vec_off(idx);
87  }
88 
89  virtual vec_store::ptr shallow_copy() {
90  // TODO the vector offsets may also be very large.
91  return mem_vv_store::ptr(new mem_vv_store(*this));
92  }
93  virtual vec_store::const_ptr shallow_copy() const {
94  // TODO the vector offsets may also be very large.
95  return mem_vv_store::ptr(new mem_vv_store(*this));
96  }
97 };
98 
99 }
100 
101 }
102 
103 #endif