2 N-Power rounding method in Concurrenthashmap

Source: Internet
Author: User

Recently see the source code of the Concurrenthashmap class in the JDK, which has a function:

/*** Returns a power of both table size for the given desired capacity. * See Hackers Delight, SEC 3.2*  /private static final int tablesizefor (int c) { int n = c-1; n |= N >>> ; 1 n|= n >>> 2 n|= n >>> 4 n|= n >>> 8 n|= n >>>
                   
                    return (n < 0)? 1: (n >= maximum_capacity)? Maximum_capacity:n + 1
                    ;} 
                                

I can't see what this is, but then I looked at the book "Hackers Delight" (the Mystery of the efficient program), only to know that this function is used to calculate the n power of C rounded up to 2. The functions in the book are as follows:

"Hackers delight" has been added to the book list.

Http://www.cnblogs.com/katsura/p/4134737.html

2 N-Power rounding method in Concurrenthashmap (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.