获取比某个数大的最小2次幂数

static final int tableSizeFor(int cap) {
int n = cap - 1;
n |= n >>> 1;
n |= n >>> 2;
n |= n >>> 4;
n |= n >>> 8;
n |= n >>> 16;
return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
}

——来自jdk1.8 HashMap 类代码源

猜你喜欢

转载自www.cnblogs.com/Trappist-1/p/10602922.html