[
https://issues.apache.org/jira/browse/HADOOP-3398?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Chris Douglas updated HADOOP-3398:
----------------------------------
Description:
ReduceTask computes the "closest power of 2" using loops
{code}
private static int getClosestPowerOf2(int value) {
int power = 0;
int approx = 1;
while (approx < value) {
++power;
approx = (approx << 1);
}
if ((value - (approx >> 1)) < (approx - value)) {
--power;
}
return power;
}
{code}
This could be improved.
was:
ReduceTask computes the "closest power of 2" using loops
{code}
private static int getClosestPowerOf2(int value) {
final int hob = Integer.highestOneBit(value);
return Integer.numberOfTrailingZeros(hob) +
Math.min((hob >>> 1) & value, 1);
int power = 0;
int approx = 1;
while (approx < value) {
++power;
approx = (approx << 1);
}
if ((value - (approx >> 1)) < (approx - value)) {
--power;
}
return power;
}
{code}
This could be improved.
> ReduceTask::closestPowerOf2 is inefficient
> ------------------------------------------
>
> Key: HADOOP-3398
> URL: https://issues.apache.org/jira/browse/HADOOP-3398
> Project: Hadoop Core
> Issue Type: Bug
> Components: mapred
> Reporter: Chris Douglas
> Assignee: Chris Douglas
> Priority: Trivial
> Fix For: 0.18.0
>
> Attachments: 3398-0.patch
>
>
> ReduceTask computes the "closest power of 2" using loops
> {code}
> private static int getClosestPowerOf2(int value) {
> int power = 0;
> int approx = 1;
> while (approx < value) {
> ++power;
> approx = (approx << 1);
> }
> if ((value - (approx >> 1)) < (approx - value)) {
> --power;
> }
> return power;
> }
> {code}
> This could be improved.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.