uselessfile.cpp

来自「VC7.1中如果将char*作为key的话需要重载关于char*的hash_co」· C++ 代码 · 共 37 行

CPP
37
字号
#define BitsOf(type) (8*sizeof(type))
typedef unsigned Int; // define your type of UNSIGNED integer.

inline int FastEstimateLeading0s(Int a)
{
    if (a) {
        int i = 0;
        for(int j = BitsOf(Int) / 2; !(a >> j); j>>=1)
            i += j;
        return i;
    }
    return BitsOf(Int);
}

inline int EvenRound(int i)
{
    return (i | 1) - 1;
}

Int isqrt(Int a)
{
    int i = FastEstimateLeading0s(a);

    a <<= i = EvenRound(i);
    Int rem = 0, root = 0;
    for(int k = (BitsOf(Int) - i) >> 1; k; --k)
    {
        root <<= 1;
        rem = (rem << 2) + ( a >> (BitsOf(Int) - 2));
        a <<= 2;
        if (root < rem)
            rem -= (++ root) ++;
    }

    return root >> 1;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?