comparison src/Matcher.cpp @ 208:9a8fc47d4f93 memory

Make some checks optional
author Chris Cannam
date Fri, 27 Feb 2015 12:59:37 +0000
parents 0159aff8c4c5
children d46be43c0738
comparison
equal deleted inserted replaced
207:0159aff8c4c5 208:9a8fc47d4f93
109 bool 109 bool
110 Matcher::isColAvailable(int j) 110 Matcher::isColAvailable(int j)
111 { 111 {
112 if (m_firstPM) { 112 if (m_firstPM) {
113 for (int i = 0; i < int(m_first.size()); ++i) { 113 for (int i = 0; i < int(m_first.size()); ++i) {
114 if (j >= m_first[i] && 114 if (j >= m_first[i] && j < m_last[i]) {
115 j < int(m_first[i] + m_bestPathCost[i].size())) {//!!! m_last[i]?
116 if (m_bestPathCost[i][j - m_first[i]] != InvalidPathCost) { 115 if (m_bestPathCost[i][j - m_first[i]] != InvalidPathCost) {
117 return true; 116 return true;
118 } 117 }
119 } 118 }
120 } 119 }
139 138
140 pair<int, int> 139 pair<int, int>
141 Matcher::getColRangeForRow(int i) 140 Matcher::getColRangeForRow(int i)
142 { 141 {
143 if (m_firstPM) { 142 if (m_firstPM) {
143 #ifdef PERFORM_ERROR_CHECKS
144 if (i < 0 || i >= int(m_first.size())) { 144 if (i < 0 || i >= int(m_first.size())) {
145 cerr << "ERROR: Matcher::getColRangeForRow(" << i << "): Index out of range" 145 cerr << "ERROR: Matcher::getColRangeForRow(" << i << "): Index out of range"
146 << endl; 146 << endl;
147 throw "Index out of range"; 147 throw "Index out of range";
148 } else { 148 }
149 return pair<int, int>(m_first[i], m_last[i]); 149 #endif
150 } 150 return pair<int, int>(m_first[i], m_last[i]);
151 } else { 151 } else {
152 return m_otherMatcher->getRowRangeForCol(i); 152 return m_otherMatcher->getRowRangeForCol(i);
153 } 153 }
154 } 154 }
155 155
156 pair<int, int> 156 pair<int, int>
157 Matcher::getRowRangeForCol(int i) 157 Matcher::getRowRangeForCol(int i)
158 { 158 {
159 if (m_firstPM) { 159 if (m_firstPM) {
160 160 #ifdef PERFORM_ERROR_CHECKS
161 if (i < 0 || i >= int(m_otherMatcher->m_first.size())) { 161 if (i < 0 || i >= int(m_otherMatcher->m_first.size())) {
162 cerr << "ERROR: Matcher::getRowRangeForCol(" << i << "): Index out of range" 162 cerr << "ERROR: Matcher::getRowRangeForCol(" << i << "): Index out of range"
163 << endl; 163 << endl;
164 throw "Index out of range"; 164 throw "Index out of range";
165 } else { 165 }
166 return pair<int, int>(m_otherMatcher->m_first[i], 166 #endif
167 m_otherMatcher->m_last[i]); 167 return pair<int, int>(m_otherMatcher->m_first[i],
168 } 168 m_otherMatcher->m_last[i]);
169
170 } else { 169 } else {
171 return m_otherMatcher->getColRangeForRow(i); 170 return m_otherMatcher->getColRangeForRow(i);
172 } 171 }
173 } 172 }
174 173
175 distance_t 174 distance_t
176 Matcher::getDistance(int i, int j) 175 Matcher::getDistance(int i, int j)
177 { 176 {
178 if (m_firstPM) { 177 if (m_firstPM) {
178 #ifdef PERFORM_ERROR_CHECKS
179 if (!isInRange(i, j)) { 179 if (!isInRange(i, j)) {
180 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): " 180 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): "
181 << "Location is not in range" << endl; 181 << "Location is not in range" << endl;
182 throw "Distance not available"; 182 throw "Distance not available";
183 } 183 }
184 #endif
184 distance_t dist = m_distance[i][j - m_first[i]]; 185 distance_t dist = m_distance[i][j - m_first[i]];
186 #ifdef PERFORM_ERROR_CHECKS
185 if (dist == InvalidDistance) { 187 if (dist == InvalidDistance) {
186 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): " 188 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): "
187 << "Location is in range, but distance (" 189 << "Location is in range, but distance ("
188 << distance_print_t(dist) 190 << distance_print_t(dist)
189 << ") is invalid or has not been set" << endl; 191 << ") is invalid or has not been set" << endl;
190 throw "Distance not available"; 192 throw "Distance not available";
191 } 193 }
194 #endif
192 return dist; 195 return dist;
193 } else { 196 } else {
194 return m_otherMatcher->getDistance(j, i); 197 return m_otherMatcher->getDistance(j, i);
195 } 198 }
196 } 199 }
197 200
198 void 201 void
199 Matcher::setDistance(int i, int j, distance_t distance) 202 Matcher::setDistance(int i, int j, distance_t distance)
200 { 203 {
201 if (m_firstPM) { 204 if (m_firstPM) {
205 #ifdef PERFORM_ERROR_CHECKS
202 if (!isInRange(i, j)) { 206 if (!isInRange(i, j)) {
203 cerr << "ERROR: Matcher::setDistance(" << i << ", " << j << ", " 207 cerr << "ERROR: Matcher::setDistance(" << i << ", " << j << ", "
204 << distance_print_t(distance) 208 << distance_print_t(distance)
205 << "): Location is out of range" << endl; 209 << "): Location is out of range" << endl;
206 throw "Indices out of range"; 210 throw "Indices out of range";
207 } 211 }
212 #endif
208 m_distance[i][j - m_first[i]] = distance; 213 m_distance[i][j - m_first[i]] = distance;
209 } else { 214 } else {
210 m_otherMatcher->setDistance(j, i, distance); 215 m_otherMatcher->setDistance(j, i, distance);
211 } 216 }
212 } 217 }
244 249
245 void 250 void
246 Matcher::setPathCost(int i, int j, advance_t dir, pathcost_t pathCost) 251 Matcher::setPathCost(int i, int j, advance_t dir, pathcost_t pathCost)
247 { 252 {
248 if (m_firstPM) { 253 if (m_firstPM) {
254 #ifdef PERFORM_ERROR_CHECKS
249 if (!isInRange(i, j)) { 255 if (!isInRange(i, j)) {
250 cerr << "ERROR: Matcher::setPathCost(" << i << ", " << j << ", " 256 cerr << "ERROR: Matcher::setPathCost(" << i << ", " << j << ", "
251 << dir << ", " << pathCost 257 << dir << ", " << pathCost
252 << "): Location is out of range" << endl; 258 << "): Location is out of range" << endl;
253 throw "Indices out of range"; 259 throw "Indices out of range";
254 } 260 }
261 #endif
255 m_advance[i][j - m_first[i]] = dir; 262 m_advance[i][j - m_first[i]] = dir;
256 m_bestPathCost[i][j - m_first[i]] = pathCost; 263 m_bestPathCost[i][j - m_first[i]] = pathCost;
257 } else { 264 } else {
258 if (dir == AdvanceThis) { 265 if (dir == AdvanceThis) {
259 dir = AdvanceOther; 266 dir = AdvanceOther;
462 469
463 advance_t 470 advance_t
464 Matcher::getAdvance(int i, int j) 471 Matcher::getAdvance(int i, int j)
465 { 472 {
466 if (m_firstPM) { 473 if (m_firstPM) {
474 #ifdef PERFORM_ERROR_CHECKS
467 if (!isInRange(i, j)) { 475 if (!isInRange(i, j)) {
468 cerr << "ERROR: Matcher::getAdvance(" << i << ", " << j << "): " 476 cerr << "ERROR: Matcher::getAdvance(" << i << ", " << j << "): "
469 << "Location is not in range" << endl; 477 << "Location is not in range" << endl;
470 throw "Advance not available"; 478 throw "Advance not available";
471 } 479 }
480 #endif
472 return m_advance[i][j - m_first[i]]; 481 return m_advance[i][j - m_first[i]];
473 } else { 482 } else {
474 return m_otherMatcher->getAdvance(j, i); 483 return m_otherMatcher->getAdvance(j, i);
475 } 484 }
476 } 485 }