--- jsr166/src/extra166y/CustomConcurrentHashMap.java 2009/08/12 04:02:45 1.4 +++ jsr166/src/extra166y/CustomConcurrentHashMap.java 2010/09/01 23:26:57 1.11 @@ -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); @@ -533,9 +533,12 @@ 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]; } @@ -956,6 +959,10 @@ public class CustomConcurrentHashMap