| 1199 | } |
| 1200 | |
| 1201 | int PAGE_RES_IT::cmp(const PAGE_RES_IT &other) const { |
| 1202 | ASSERT_HOST(page_res == other.page_res); |
| 1203 | if (other.block_res == NULL) { |
| 1204 | // other points to the end of the page. |
| 1205 | if (block_res == NULL) |
| 1206 | return 0; |
| 1207 | return -1; |
| 1208 | } |
| 1209 | if (block_res == NULL) { |
| 1210 | return 1; // we point to the end of the page. |
| 1211 | } |
| 1212 | if (block_res == other.block_res) { |
| 1213 | if (other.row_res == NULL || row_res == NULL) { |
| 1214 | // this should only happen if we hit an image block. |
| 1215 | return 0; |
| 1216 | } |
| 1217 | if (row_res == other.row_res) { |
| 1218 | // we point to the same block and row. |
| 1219 | ASSERT_HOST(other.word_res != NULL && word_res != NULL); |
| 1220 | if (word_res == other.word_res) { |
| 1221 | // we point to the same word! |
| 1222 | return 0; |
| 1223 | } |
| 1224 | |
| 1225 | WERD_RES_IT word_res_it(&row_res->word_res_list); |
| 1226 | for (word_res_it.mark_cycle_pt(); !word_res_it.cycled_list(); |
| 1227 | word_res_it.forward()) { |
| 1228 | if (word_res_it.data() == word_res) { |
| 1229 | return -1; |
| 1230 | } else if (word_res_it.data() == other.word_res) { |
| 1231 | return 1; |
| 1232 | } |
| 1233 | } |
| 1234 | ASSERT_HOST("Error: Incomparable PAGE_RES_ITs" == NULL); |
| 1235 | } |
| 1236 | |
| 1237 | // we both point to the same block, but different rows. |
| 1238 | ROW_RES_IT row_res_it(&block_res->row_res_list); |
| 1239 | for (row_res_it.mark_cycle_pt(); !row_res_it.cycled_list(); |
| 1240 | row_res_it.forward()) { |
| 1241 | if (row_res_it.data() == row_res) { |
| 1242 | return -1; |
| 1243 | } else if (row_res_it.data() == other.row_res) { |
| 1244 | return 1; |
| 1245 | } |
| 1246 | } |
| 1247 | ASSERT_HOST("Error: Incomparable PAGE_RES_ITs" == NULL); |
| 1248 | } |
| 1249 | |
| 1250 | // We point to different blocks. |
| 1251 | BLOCK_RES_IT block_res_it(&page_res->block_res_list); |
| 1252 | for (block_res_it.mark_cycle_pt(); |
| 1253 | !block_res_it.cycled_list(); block_res_it.forward()) { |
| 1254 | if (block_res_it.data() == block_res) { |
| 1255 | return -1; |
| 1256 | } else if (block_res_it.data() == other.block_res) { |
| 1257 | return 1; |
| 1258 | } |
no test coverage detected