File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
main/java/com/graphhopper/util
test/java/com/graphhopper/util Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -88,11 +88,15 @@ static String packageToPath(Package pkg) {
88
88
}
89
89
90
90
public static int countBitValue (int maxTurnCosts ) {
91
- double val = Math .log (maxTurnCosts ) / Math .log (2 );
92
- int intVal = (int ) val ;
93
- if (val == intVal )
94
- return intVal ;
95
- return intVal + 1 ;
91
+ if (maxTurnCosts < 0 )
92
+ throw new IllegalArgumentException ("maxTurnCosts cannot be negative " + maxTurnCosts );
93
+
94
+ int counter = 0 ;
95
+ while (maxTurnCosts > 0 ) {
96
+ maxTurnCosts >>= 1 ;
97
+ counter ++;
98
+ }
99
+ return counter ++;
96
100
}
97
101
98
102
public static void loadProperties (Map <String , String > map , Reader tmpReader ) throws IOException {
Original file line number Diff line number Diff line change @@ -47,7 +47,12 @@ public void tearDown() {
47
47
48
48
@ Test
49
49
public void testCountBitValue () throws Exception {
50
- assertEquals (2 , Helper .countBitValue (4 ));
50
+ assertEquals (1 , Helper .countBitValue (1 ));
51
+ assertEquals (2 , Helper .countBitValue (2 ));
52
+ assertEquals (2 , Helper .countBitValue (3 ));
53
+ assertEquals (3 , Helper .countBitValue (4 ));
54
+ assertEquals (3 , Helper .countBitValue (7 ));
55
+ assertEquals (4 , Helper .countBitValue (8 ));
51
56
assertEquals (5 , Helper .countBitValue (20 ));
52
57
}
53
58
You can’t perform that action at this time.
0 commit comments