| 455 | } |
| 456 | |
| 457 | void MinorKey::selectFirstRows (const int k, const MinorKey& mk) |
| 458 | { |
| 459 | int hitBits = 0; /* the number of bits we have hit; in the end, this |
| 460 | has to be equal to k, the dimension of the minor */ |
| 461 | int blockIndex = -1; /* the index of the current int in mk */ |
| 462 | unsigned int highestInt = 0; /* the new highest block of this MinorKey */ |
| 463 | /* We determine which ints of mk we can copy. Their indices will be |
| 464 | 0, 1, ..., blockIndex - 1. And highestInt is going to capture the highest |
| 465 | int (which may be only a portion of the corresponding int in mk. |
| 466 | We loop until hitBits = k: */ |
| 467 | while (hitBits < k) |
| 468 | { |
| 469 | blockIndex++; |
| 470 | highestInt = 0; |
| 471 | unsigned int currentInt = mk.getRowKey(blockIndex); |
| 472 | unsigned int shiftedBit = 1; |
| 473 | int exponent = 0; |
| 474 | /* invariant in the loop: shiftedBit = 2^exponent */ |
| 475 | while (exponent < 32 && hitBits < k) |
| 476 | { |
| 477 | if (shiftedBit & currentInt) |
| 478 | { |
| 479 | highestInt += shiftedBit; |
| 480 | hitBits++; |
| 481 | } |
| 482 | shiftedBit = shiftedBit << 1; |
| 483 | exponent++; |
| 484 | } |
| 485 | } |
| 486 | /* free old memory */ |
| 487 | omfree(_rowKey); |
| 488 | _rowKey = NULL; |
| 489 | _numberOfRowBlocks = blockIndex + 1; |
| 490 | /* allocate memory for new entries in _rowKey; */ |
| 491 | _rowKey = (unsigned*)omAlloc(_numberOfRowBlocks*sizeof(unsigned)); |
| 492 | /* copying values from mk to this MinorKey */ |
| 493 | for (int r = 0; r < blockIndex; r++) |
| 494 | _rowKey[r] = mk.getRowKey(r); |
| 495 | _rowKey[blockIndex] = highestInt; |
| 496 | } |
| 497 | |
| 498 | void MinorKey::selectFirstColumns (const int k, const MinorKey& mk) |
| 499 | { |