5 ms·
shouldn't it be var actualSize = 1 << Integer.highestOneBit(approxSize - 1); ?
by markrages 2y ago
shouldn't it be
var actualSize = 1 << Integer.highestOneBit(approxSize - 1);
?
- mananaysiempre 2y agoNope. I don’t know why the Java folks decided not to use the fairly standard verb “isolate” for this method, but that’s what it is[1]: > public static int highestOneBit(int i) > Returns an int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int value. Returns zero if the specified value has no one-bits in its two's complement binary representation, that is, if it is equal to zero. There isn’t a straight floor(log2(·)) as far as I can tell, only Integer.numberOfLeadingZeros, and turning the former into the latter is annoying enough[2] that I wouldn’t prefer it here. [1] https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#highestOneBit-int- https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.... [2] https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#numberOfLeadingZeros-int- https://docs.oracle.com/javase/8/docs/api/java/lang/Integer....
- markrages 2y agoThanks. What a weird API.