. - , , .
, , .
, , . , . , , [2 ^ i, 2 ^ i], { , , , }.
1)
.. [X, Y], X * Y, [x, y] (x, y) :
(y * X + x):
unsigned position( rx, ry )
{
unsigned x = rx;
unsigned y = rx;
unsigned part = 1;
unsigned pos = 0;
while( ( x != 0 ) && ( y != 0 ) ) {
unsigned const lowest_bit_x = ( x % 2 );
unsigned const lowest_bit_y = ( y % 2 );
pos += ( ((2*lowest_bit_y) + lowest_bit_x) * part );
x /= 2;
y /= 2;
part *= 4;
}
return pos;
}
, , .
, .
, X * Y, (2 ^ (2 * k)), , X Y . , sqaures.
benfits (x, y).
2), then try to find the best way to run the submatrix elements in fits () and place (). Not sure what it is, not necessarily as it is now. Basically, a submatrix of size [x, y] should be in no more than y * log (x) * log (y) blocks that are adjacent in the array representation, but they all fit in no more than 4 blocks of size 4 * x * y. So finally, for matrices that are smaller than the memory cache page, you will get no more than 4 memory cache breaks, while your source code may break y times.