我有一种方法可以将value转换为长度length的newBase数。
英文的逻辑是:
If we calculated every possible combination of numbers from 0 to (c-1)
with a length of x
what set would occur at point i
虽然下面的方法确实工作得很好,因为使用了非常大的数字,它可能需要很长时间才能完成:
例如 value=(((65536^480000)-1)/2), newbase=(65536), length=(480000) 在 64 位架构,四核 PC 上大约需要一个小时才能完成。
private int[] GetValues(BigInteger value, int newBase, int length)
{
Stack<int> result = new Stack<int>();
while (value > 0)
{
result.Push((int)(value % newBase));
if (value < newBase)
value = 0;
else
value = value / newBase;
}
for (var i = result.Count; i < length; i++)
{
result.Push(0);
}
return result.ToArray();
}
我的问题是,如何将此方法更改为允许多个线程计算部分数字的方法?
我正在使用 C#,但如果你不熟悉它,那么伪代码也可以。
注意:该方法来自这个问题:Cartesian product subset returns set of most 0