| 341 | #endif |
| 342 | |
| 343 | MinorKey MinorKey::getSubMinorKey (const int absoluteEraseRowIndex, |
| 344 | const int absoluteEraseColumnIndex) const |
| 345 | { |
| 346 | int rowBlock = absoluteEraseRowIndex / 32; |
| 347 | int exponent = absoluteEraseRowIndex % 32; |
| 348 | unsigned int newRowBits = getRowKey(rowBlock) - (1 << exponent); |
| 349 | int highestRowBlock = getNumberOfRowBlocks() - 1; |
| 350 | /* highestRowBlock will finally contain the highest block index with |
| 351 | non-zero bit pattern */ |
| 352 | if ((newRowBits == 0) && (rowBlock == highestRowBlock)) |
| 353 | { |
| 354 | /* we have thus nullified the highest block; |
| 355 | we can now forget about the highest block... */ |
| 356 | highestRowBlock -= 1; |
| 357 | while (getRowKey(highestRowBlock) == 0) /* ...and maybe even some more |
| 358 | zero-blocks */ |
| 359 | highestRowBlock -= 1; |
| 360 | } |
| 361 | /* highestRowBlock now contains the highest row block index with non-zero |
| 362 | bit pattern */ |
| 363 | |
| 364 | int columnBlock = absoluteEraseColumnIndex / 32; |
| 365 | exponent = absoluteEraseColumnIndex % 32; |
| 366 | unsigned int newColumnBits = getColumnKey(columnBlock) - (1 << exponent); |
| 367 | int highestColumnBlock = getNumberOfColumnBlocks() - 1; |
| 368 | /* highestColumnBlock will finally contain the highest block index with |
| 369 | non-zero bit pattern */ |
| 370 | if ((newColumnBits == 0) && (columnBlock == highestColumnBlock)) |
| 371 | { |
| 372 | /* we have thus nullified the highest block; |
| 373 | we can now forget about the highest block... */ |
| 374 | highestColumnBlock -= 1; |
| 375 | while (getColumnKey(highestColumnBlock) == 0) /* ...and maybe even some |
| 376 | more zero-blocks */ |
| 377 | highestColumnBlock -= 1; |
| 378 | } |
| 379 | /* highestColumnBlock now contains the highest column block index with |
| 380 | non-zero bit pattern */ |
| 381 | |
| 382 | MinorKey result(highestRowBlock + 1, _rowKey, highestColumnBlock + 1, |
| 383 | _columnKey); |
| 384 | /* This is just a copy with maybe some leading bit blocks omitted. We still |
| 385 | need to re-define the row block at index 'rowBlock' and the column block |
| 386 | at index 'columnBlock': */ |
| 387 | if ((newRowBits != 0) || (rowBlock < getNumberOfRowBlocks() - 1)) |
| 388 | result.setRowKey(rowBlock, newRowBits); |
| 389 | if ((newColumnBits != 0) || (columnBlock < getNumberOfColumnBlocks() - 1)) |
| 390 | result.setColumnKey(columnBlock, newColumnBits); |
| 391 | |
| 392 | #ifndef SING_NDEBUG |
| 393 | /* let's check that the number of selected rows and columns are equal; |
| 394 | (this check is only performed in the debug version) */ |
| 395 | assume(result.getSetBits(1) == result.getSetBits(2)); |
| 396 | #endif |
| 397 | |
| 398 | return result; |
| 399 | } |
| 400 |
no test coverage detected