int rounded = number >= MAXIMUM_CAPACITY ? MAXIMUM_CAPACITY
: (rounded = Integer.highestOneBit(number)) != 0 ?
(Integer.bitCount(number) > 1) ? rounded << 1 : rounded
: 1;

分析rounded求解过程:

Created with Raphaël 2.1.0开始number >= 2^302^30返回rounded = Integer.highestOneBit(number)rounded !=0 Integer.bitCount(number) > 1rounded << 1 rounded1yesnoyesnoyesno

流程图

Created with Raphaël 2.1.0开始number >= 2^302^30返回rounded,求最接近的r=2^nrounded !=0 number >rnumber>r 则两倍之本来就是2^n的值得round1yesnoyesnoyesno

流程图分析

05-11 20:14