C++实现平方的安全方法(redis的实现)

/* Our hash table capability is a power of two */
static unsigned long _dictNextPower(unsigned long size)
{
    unsigned long i = DICT_HT_INITIAL_SIZE; //DICT_HT_INITIAL_SIZE=4

    if (size >= LONG_MAX) return LONG_MAX;
    while(1) {
        if (i >= size)
            return i;
        i *= 2;
    }
}

posted @ 2012-05-31 13:29  MXi4oyu  阅读(182)  评论(0编辑  收藏  举报