FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
vv_store.h
1 #ifndef __VV_STORE_H__
2 #define __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 "vec_store.h"
24 
25 namespace fm
26 {
27 
28 namespace detail
29 {
30 
31 class vv_store: public vec_store
32 {
33  // The offsets (in #bytes) of the vectors in the data array.
34  // The last offset is the end of the last vector.
35  std::vector<off_t> vec_offs;
36  vec_store::ptr store;
37 
38  std::vector<off_t> get_rel_offs(off_t loc, size_t size) const;
39 public:
40  typedef std::shared_ptr<vv_store> ptr;
41  typedef std::shared_ptr<const vv_store> const_ptr;
42 
43  static bool is_vector_vector(const vec_store &vec) {
44  return vec.get_entry_size() == 0;
45  }
46 
47  static ptr cast(vec_store::ptr vec) {
48  assert(is_vector_vector(*vec));
49  return std::static_pointer_cast<vv_store>(vec);
50  }
51 
52  static ptr create(const scalar_type &type, bool in_mem);
53 
54  vv_store(const scalar_type &type, bool in_mem);
55  vv_store(const std::vector<off_t> &offs, vec_store::ptr store);
56 
57  const vec_store &get_data() const {
58  return *store;
59  }
60  vec_store &get_data() {
61  return *store;
62  }
63  off_t get_vec_off(off_t idx) const {
64  return vec_offs[idx];
65  }
66 
67  size_t get_num_bytes(off_t idx) const {
68  return vec_offs[idx + 1] - vec_offs[idx];
69  }
70 
71  size_t get_length(off_t idx) const {
72  return get_num_bytes(idx) / get_type().get_size();
73  }
74 
75  size_t get_num_vecs() const {
76  return vec_offs.size() - 1;
77  }
78 
79  virtual size_t get_num_bytes() const {
80  return store->get_length() * store->get_type().get_size();
81  }
82  vec_store::const_ptr cat() const;
83 
84  virtual vec_store::ptr deep_copy() const;
85 
86  virtual bool append(const vec_store &vec);
87  virtual bool append(std::vector<vec_store::const_ptr>::const_iterator vec_it,
88  std::vector<vec_store::const_ptr>::const_iterator vec_end);
89 
90  virtual std::shared_ptr<const local_vec_store> get_portion(off_t start,
91  size_t len) const;
92  virtual std::shared_ptr<local_vec_store> get_portion(off_t loc,
93  size_t size);
94 
95  /*
96  * The following methods aren't supported in the vv_store.
97  */
98 
99  virtual bool resize(size_t new_length) {
100  assert(0);
101  return false;
102  }
103  virtual size_t get_portion_size() const {
104  assert(0);
105  return -1;
106  }
107  virtual vec_store::ptr sort_with_index() {
108  assert(0);
109  return vec_store::ptr();
110  }
111  virtual void sort() {
112  assert(0);
113  }
114  virtual bool is_sorted() const {
115  return false;
116  }
117 
118  virtual void reset_data() {
119  assert(0);
120  }
121  virtual void set_data(const set_vec_operate &op) {
122  assert(0);
123  }
124  virtual void set_data(const set_vv_operate &op) {
125  assert(0);
126  }
127  virtual bool set_portion(std::shared_ptr<const local_vec_store> store,
128  off_t off) {
129  assert(0);
130  return false;
131  }
132 
133  virtual std::shared_ptr<matrix_store> conv2mat(size_t nrow,
134  size_t ncol, bool byrow) {
135  return std::shared_ptr<matrix_store>();
136  }
137 };
138 
139 }
140 
141 }
142 
143 #endif