首先,我将重新定义符号:
rowCount = N
columnCount = M
如果 page 无关紧要,则首先将 更改index
为 page-ignorant:
pageSize = rowCount * columnCount
index = index % pageSize
然后,如果您首先迭代行(我的意思是当index
移动时,它会进入下一列 - 所以它会沿着一行滑动,并在行的末尾进入下一行)然后:
rowNumber = floor(index / columnCount)
columnNumber = index - rowNumber * columnCount
2x3
网格最后一个索引的示例:
rowCount = 2
columnCount = 3
第 1 页
c0 c1 c2
----------
|0 |1 |2 | r0
----------
|3 |4 |5 | r1
----------
第2页
c0 c1 c2
----------
|6 |7 |8 | r0
----------
|9 |10|11| r1
----------
那时index = 5
:
pageSize = 2*3 = 6
index = 5 % 6 = 5
rowNumber = floor(5 / 3) = 1
columnNumber = 5 - 1 * 3 = 2
那时index = 11
:
pageSize = 6 (as above)
index = 11 % 6 = 5
rowNumber = 1 (as above)
columnNumber = 2 (as above)