--- jsr166/src/extra166y/CustomConcurrentHashMap.java 2009/07/22 17:50:01 1.3 +++ jsr166/src/extra166y/CustomConcurrentHashMap.java 2011/08/03 14:44:33 1.18 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ package extra166y; @@ -53,10 +53,10 @@ import sun.misc.Unsafe; * (STRONG, * new Equivalence() { * public boolean equal(Person k, Object x) { - * return x instanceOf Person && k.name.equals(((Person)x).name); + * return x instanceof Person && k.name.equals(((Person)x).name); * } * public int hash(Object x) { - * return (x instanceOf Person)? ((Person)x).name.hashCode() : 0; + * return (x instanceof Person) ? ((Person)x).name.hashCode() : 0; * } * }, * STRONG, EQUALS, 0); @@ -81,7 +81,7 @@ import sun.misc.Unsafe; * via a background thread common across all maps. Because of the * potential for asynchronous clearing of References, methods such as * containsValue have weaker guarantees than you might - * expect even in the absence of other explicity concurrent + * expect even in the absence of other explicitly concurrent * operations. For example containsValue(value) may * return true even if value is no longer available upon * return from the method. @@ -236,7 +236,7 @@ public class CustomConcurrentHashMap>> SEGMENT_BITS); if (sc < MIN_SEGMENT_CAPACITY) sc = MIN_SEGMENT_CAPACITY; - else if (sc > MAX_SEGMENT_CAPACITY) - sc = MAX_SEGMENT_CAPACITY; - this.initialSegmentCapacity = sc; + int capacity = MIN_SEGMENT_CAPACITY; // ensure power of two + while (capacity < sc) + capacity <<= 1; + if (capacity > MAX_SEGMENT_CAPACITY) + capacity = MAX_SEGMENT_CAPACITY; + this.initialSegmentCapacity = capacity; } this.segments = (Segment[])new Segment[NSEGMENTS]; } @@ -629,7 +633,7 @@ public class CustomConcurrentHashMap>> SEGMENT_SHIFT) & SEGMENT_MASK; Segment seg = segs[index]; if (seg == null) { - synchronized(segs) { + synchronized (segs) { seg = segs[index]; if (seg == null) { seg = new Segment(); @@ -696,7 +700,7 @@ public class CustomConcurrentHashMapnull if + * @return the value associated with the key or null if * there is no mapping. * @throws NullPointerException if the specified key is null */ @@ -712,7 +716,7 @@ public class CustomConcurrentHashMap= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)sum; + return (sum >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) sum; } /** @@ -1065,7 +1069,7 @@ public class CustomConcurrentHashMap * if (map.containsKey(key)) @@ -1078,7 +1082,7 @@ public class CustomConcurrentHashMap * * except that the action is performed atomically. Some - * attemmpted operations on this map by other threads may be + * attempted operations on this map by other threads may be * blocked while computation is in progress. Because this function * is invoked within atomicity control, the computation should be * short and simple. The most common usage is to construct a new @@ -1145,7 +1149,7 @@ public class CustomConcurrentHashMap * - * except that the action is performed atomically. Some attemmpted + * except that the action is performed atomically. Some attempted * operations on this map by other threads may be blocked while * computation is in progress. * @@ -1154,7 +1158,7 @@ public class CustomConcurrentHashMap * map.compute(word, new RemappingFunction<String,Integer>() { * public Integer remap(String k, Integer v) { - * return v == null? 1 : v + 1; + * return (v == null) ? 1 : v + 1; * }}); * * @@ -1410,7 +1414,8 @@ public class CustomConcurrentHashMap e = (Map.Entry)o; - return CustomConcurrentHashMap.this.remove(e.getKey(), e.getValue()); + return CustomConcurrentHashMap.this.remove(e.getKey(), + e.getValue()); } public int size() { return CustomConcurrentHashMap.this.size(); @@ -1554,7 +1559,7 @@ public class CustomConcurrentHashMap e : entrySet()) { s.writeObject(e.getKey()); @@ -1565,11 +1570,11 @@ public class CustomConcurrentHashMap