TdZdd  1.1
A top-down/breadth-first decision diagram manipulation framework
DataTable.hpp
1 /*
2  * TdZdd: a Top-down/Breadth-first Decision Diagram Manipulation Framework
3  * by Hiroaki Iwashita <iwashita@erato.ist.hokudai.ac.jp>
4  * Copyright (c) 2014 ERATO MINATO Project
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include <cassert>
28 #include <ostream>
29 
30 #include "../util/MyVector.hpp"
31 
32 namespace tdzdd {
33 
34 template<typename T>
35 class DataTable {
36  MyVector<MyVector<T> > table;
37 
38 // DataTable(DataTable const& o);
39 // DataTable& operator=(DataTable const& o);
40 
41 public:
46  DataTable(int n = 0)
47  : table(n) {
48  }
49 
50  DataTable(DataTable const& o)
51  : table(o.table) {
52  }
53 
54  DataTable& operator=(DataTable const& o) {
55  table = o.table;
56  return *this;
57  }
58 
59 // template<typename U>
60 // DataTable(DataTable<U> const& o)
61 // : table(o.table) {
62 // }
63 //
64 // template<typename U>
65 // DataTable& operator=(DataTable<U> const& o) {
66 // table = o.table;
67 // return *this;
68 // }
69 
70 // /*
71 // * Imports the table that can be broken.
72 // * @param o the table.
73 // */
74 // void moveFrom(DataTable& o) {
75 // this->~DataTable();
76 // numRows_ = o.numRows_;
77 // rowSize_ = o.rowSize_;
78 // rowCapacity_ = o.rowCapacity_;
79 // table = o.table;
80 //
81 // o.numRows_ = 0;
82 // o.rowSize_ = 0;
83 // o.rowCapacity_ = 0;
84 // o.table = 0;
85 // }
86 
91  void init(int n = 0) {
92  table.clear();
93  table.resize(n);
94  }
95 
100  void setNumRows(int n) {
101  table.resize(n);
102  }
103 
109  void initRow(int i, size_t size) {
110  table[i].clear();
111  table[i].resize(size);
112  }
113 
114 // /**
115 // * Clears and initializes a row.
116 // * @param i row index.
117 // * @param size new size of the row.
118 // * @param initVal initial value of elements.
119 // * @return the new array for the row.
120 // */
121 // T* initRow(int i, size_t size, T const& initVal) {
122 // assert(0 <= i && i < numRows_);
123 // rowSize_[i] = rowCapacity_[i] = size;
124 // delete[] table[i];
125 // if (size == 0) return table[i] = 0;
126 //
127 // T* row = table[i] = new T[size];
128 // for (size_t j = 0; j < size; ++j) {
129 // row[j] = initVal;
130 // }
131 // return row;
132 // }
133 
139  size_t addColumn(int i) {
140  table[i].push_back(T());
141  return table[i].size() - 1;
142  }
143 
148  int numRows() const {
149  return table.size();
150  }
151 
156  size_t totalSize() const {
157  size_t k = 0;
158  for (size_t i = 0; i < table.size(); ++i) {
159  k += table[i].size();
160  }
161  return k;
162  }
163 
169  MyVector<T>& operator[](int i) {
170  return table[i];
171  }
172 
178  MyVector<T> const& operator[](int i) const {
179  return table[i];
180  }
181 
182  friend std::ostream& operator<<(std::ostream& os, DataTable const& o) {
183  for (int i = 0; i < o.numRows(); ++i) {
184  os << i << ": ";
185  for (size_t j = 0; j < o[i].size(); ++j) {
186  if (j != 0) os << ", ";
187  os << o.table[i][j];
188  }
189  os << "\n";
190  }
191  return os;
192  }
193 };
194 
195 } // namespace tdzdd