假设我有一行包含3 +属性A,B,C和其他Attrs
row1: A=1, B=5, C=10, Other Attrs
row2: A=1, B=5, C=10, Other Attrs
row3: A=2, B=5, C=10, Other Attrs
row4: A=2, B=5, C=10, Other Attrs
row5: A=3, B=6, C=11, Other Attrs
row6: A=3, B=6, C=11, Other Attrs
Run Code Online (Sandbox Code Playgroud)
因此,如果我想通过A,B,C,row1的组合为每一行分配组ID,则row2具有相同的组id x,第3行第4行具有组id y,第5行第6行具有组id z.
一个简单的解决方案是
group id = A * S + B * S^2 + C * S^3 (S is the max integer number)
Run Code Online (Sandbox Code Playgroud)
但我的问题是我需要一个算法来从组ID中退出A,B,C值中的每一个
例如,我需要能够从组id x单独退出A = 1,B = 5,C = 10
首先,这就足够了:
group id = A + B * S + C * S^2;
Run Code Online (Sandbox Code Playgroud)
要回到A,B和C:
A = id % S;
B = (id / S) % S;
C = (id / S^2);
Run Code Online (Sandbox Code Playgroud)
/整数除法在哪里并且%是模数.