1. 程式人生 > >獲取比某個數大的最小2次冪數

獲取比某個數大的最小2次冪數

shm map ble 最小 size fin jdk1.8 代碼 pac

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 類代碼源

獲取比某個數大的最小2次冪數