求解:90个数字哈希表与神秘数字
求解:90个数字哈希表与神秘数字 unsinged int v; // 整数
int r; // 运算结果
static const int MultiplyDeBruijnBitPosition[32] ={
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];
64位的如下: 神秘数字:0x3f79d71b4cb0a89UL
64个数字的哈希表为:
const char g_math_64[] ={0,1,48,2,57,49,28,3,61,58,50,42,38,29,17,4,62,55,59,36,53,51,
43,22,45,39,33,30,24,18,12,5,63,47,56,27,60,41,37,16,54,35,52,21,44,32,23,11,46,26,40,
15,34,20,31,10,25,14,19,9,13,8,7,6};
求log2的算法:
#define LOG2_64(v) g_math_64[(uint64_t)((v& -v) * 0x3f79d71b4cb0a89UL) >> 58]
如何写出90个数字的哈希表?
90位数字的神秘数字是多少?
请指教!谢了
[此贴子已经被作者于2019-9-24 19:22编辑过]