ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/ConcurrentHashMapV8.java
(Generate patch)

Comparing jsr166/src/jsr166e/ConcurrentHashMapV8.java (file contents):
Revision 1.52 by dl, Mon Aug 13 15:52:33 2012 UTC vs.
Revision 1.58 by jsr166, Tue Aug 14 05:55:08 2012 UTC

# Line 712 | Line 712 | public class ConcurrentHashMapV8<K, V>
712          }
713  
714          /**
715 <         * Return the TreeNode (or null if not found) for the given key
715 >         * Returns the TreeNode (or null if not found) for the given key
716           * starting at given root.
717           */
718          @SuppressWarnings("unchecked") // suppress Comparable cast warning
# Line 2327 | Line 2327 | public class ConcurrentHashMapV8<K, V>
2327          }
2328  
2329          public final void remove() {
2330 <            if (nextVal == null)
2330 >            if (nextVal == null && last == null)
2331                  advance();
2332              Node e = last;
2333              if (e == null)
# Line 2657 | Line 2657 | public class ConcurrentHashMapV8<K, V>
2657       *
2658       * @param key key with which the specified value is to be associated
2659       * @param remappingFunction the function to compute a value
2660 <     * @return the new value associated with
2661 <     *         the specified key, or null if none.
2660 >     * @return the new value associated with the specified key, or null if none
2661       * @throws NullPointerException if the specified key or remappingFunction
2662       *         is null
2663       * @throws IllegalStateException if the computation detectably
# Line 2704 | Line 2703 | public class ConcurrentHashMapV8<K, V>
2703       *
2704       * @param key key with which the specified value is to be associated
2705       * @param remappingFunction the function to compute a value
2706 <     * @return the new value associated with
2708 <     *         the specified key, or null if none.
2706 >     * @return the new value associated with the specified key, or null if none
2707       * @throws NullPointerException if the specified key or remappingFunction
2708       *         is null
2709       * @throws IllegalStateException if the computation detectably
# Line 2898 | Line 2896 | public class ConcurrentHashMapV8<K, V>
2896      }
2897  
2898      /**
2899 <     * Returns a partionable iterator of the keys in this map.
2899 >     * Returns a partitionable iterator of the keys in this map.
2900       *
2901 <     * @return a partionable iterator of the keys in this map
2901 >     * @return a partitionable iterator of the keys in this map
2902       */
2903      public Spliterator<K> keySpliterator() {
2904          return new KeyIterator<K,V>(this);
2905      }
2906  
2907      /**
2908 <     * Returns a partionable iterator of the values in this map.
2908 >     * Returns a partitionable iterator of the values in this map.
2909       *
2910 <     * @return a partionable iterator of the values in this map
2910 >     * @return a partitionable iterator of the values in this map
2911       */
2912      public Spliterator<V> valueSpliterator() {
2913          return new ValueIterator<K,V>(this);
2914      }
2915  
2916      /**
2917 <     * Returns a partionable iterator of the entries in this map.
2917 >     * Returns a partitionable iterator of the entries in this map.
2918       *
2919 <     * @return a partionable iterator of the entries in this map
2919 >     * @return a partitionable iterator of the entries in this map
2920       */
2921      public Spliterator<Map.Entry<K,V>> entrySpliterator() {
2922          return new EntryIterator<K,V>(this);
# Line 3518 | Line 3516 | public class ConcurrentHashMapV8<K, V>
3516  
3517      /**
3518       * An extended view of a ConcurrentHashMap supporting bulk
3519 <     * parallel operations. These operations are designed to be be
3519 >     * parallel operations. These operations are designed to be
3520       * safely, and often sensibly, applied even with maps that are
3521       * being concurrently updated by other threads; for example, when
3522       * computing a snapshot summary of the values in a shared
# Line 3636 | Line 3634 | public class ConcurrentHashMapV8<K, V>
3634           *
3635           * @param action the action
3636           */
3637 <        public void forEach(BiAction<K,V> action) {
3637 >        public void forEach(BiAction<K,V> action) {
3638              fjp.invoke(ForkJoinTasks.forEach
3639                         (ConcurrentHashMapV8.this, action));
3640          }
# Line 3650 | Line 3648 | public class ConcurrentHashMapV8<K, V>
3648           * which case the action is not applied).
3649           * @param action the action
3650           */
3651 <        public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3651 >        public <U> void forEach(BiFun<? super K, ? super V, ? extends U> transformer,
3652                                  Action<U> action) {
3653              fjp.invoke(ForkJoinTasks.forEach
3654                         (ConcurrentHashMapV8.this, transformer, action));
# Line 3750 | Line 3748 | public class ConcurrentHashMapV8<K, V>
3748          }
3749  
3750          /**
3751 <         * Performs the given action for each key
3751 >         * Performs the given action for each key.
3752           *
3753           * @param action the action
3754           */
3755 <        public void forEachKey(Action<K> action) {
3755 >        public void forEachKey(Action<K> action) {
3756              fjp.invoke(ForkJoinTasks.forEachKey
3757                         (ConcurrentHashMapV8.this, action));
3758          }
3759  
3760          /**
3761           * Performs the given action for each non-null transformation
3762 <         * of each key
3762 >         * of each key.
3763           *
3764           * @param transformer a function returning the transformation
3765           * for an element, or null of there is no transformation (in
3766           * which case the action is not applied).
3767           * @param action the action
3768           */
3769 <        public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3769 >        public <U> void forEachKey(Fun<? super K, ? extends U> transformer,
3770                                     Action<U> action) {
3771              fjp.invoke(ForkJoinTasks.forEachKey
3772                         (ConcurrentHashMapV8.this, transformer, action));
# Line 3880 | Line 3878 | public class ConcurrentHashMapV8<K, V>
3878          }
3879  
3880          /**
3881 <         * Performs the given action for each value
3881 >         * Performs the given action for each value.
3882           *
3883           * @param action the action
3884           */
3885 <        public void forEachValue(Action<V> action) {
3885 >        public void forEachValue(Action<V> action) {
3886              fjp.invoke(ForkJoinTasks.forEachValue
3887                         (ConcurrentHashMapV8.this, action));
3888          }
3889  
3890          /**
3891           * Performs the given action for each non-null transformation
3892 <         * of each value
3892 >         * of each value.
3893           *
3894           * @param transformer a function returning the transformation
3895           * for an element, or null of there is no transformation (in
3896           * which case the action is not applied).
3897           */
3898 <        public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3898 >        public <U> void forEachValue(Fun<? super V, ? extends U> transformer,
3899                                       Action<U> action) {
3900              fjp.invoke(ForkJoinTasks.forEachValue
3901                         (ConcurrentHashMapV8.this, transformer, action));
# Line 4009 | Line 4007 | public class ConcurrentHashMapV8<K, V>
4007          }
4008  
4009          /**
4010 <         * Perform the given action for each entry
4010 >         * Performs the given action for each entry.
4011           *
4012           * @param action the action
4013           */
4014 <        public void forEachEntry(Action<Map.Entry<K,V>> action) {
4014 >        public void forEachEntry(Action<Map.Entry<K,V>> action) {
4015              fjp.invoke(ForkJoinTasks.forEachEntry
4016                         (ConcurrentHashMapV8.this, action));
4017          }
4018  
4019          /**
4020 <         * Perform the given action for each non-null transformation
4021 <         * of each entry
4020 >         * Performs the given action for each non-null transformation
4021 >         * of each entry.
4022           *
4023           * @param transformer a function returning the transformation
4024           * for an element, or null of there is no transformation (in
4025           * which case the action is not applied).
4026           * @param action the action
4027           */
4028 <        public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4028 >        public <U> void forEachEntry(Fun<Map.Entry<K,V>, ? extends U> transformer,
4029                                       Action<U> action) {
4030              fjp.invoke(ForkJoinTasks.forEachEntry
4031                         (ConcurrentHashMapV8.this, transformer, action));
# Line 4159 | Line 4157 | public class ConcurrentHashMapV8<K, V>
4157           * @param action the action
4158           * @return the task
4159           */
4160 <        public static <K,V> ForkJoinTask<Void> forEach
4160 >        public static <K,V> ForkJoinTask<Void> forEach
4161              (ConcurrentHashMapV8<K,V> map,
4162               BiAction<K,V> action) {
4163              if (action == null) throw new NullPointerException();
# Line 4177 | Line 4175 | public class ConcurrentHashMapV8<K, V>
4175           * @param action the action
4176           * @return the task
4177           */
4178 <        public static <K,V,U> ForkJoinTask<Void> forEach
4178 >        public static <K,V,U> ForkJoinTask<Void> forEach
4179              (ConcurrentHashMapV8<K,V> map,
4180               BiFun<? super K, ? super V, ? extends U> transformer,
4181               Action<U> action) {
# Line 4304 | Line 4302 | public class ConcurrentHashMapV8<K, V>
4302  
4303          /**
4304           * Returns a task that when invoked, performs the given action
4305 <         * for each key
4305 >         * for each key.
4306           *
4307           * @param map the map
4308           * @param action the action
4309           * @return the task
4310           */
4311 <        public static <K,V> ForkJoinTask<Void> forEachKey
4311 >        public static <K,V> ForkJoinTask<Void> forEachKey
4312              (ConcurrentHashMapV8<K,V> map,
4313               Action<K> action) {
4314              if (action == null) throw new NullPointerException();
# Line 4319 | Line 4317 | public class ConcurrentHashMapV8<K, V>
4317  
4318          /**
4319           * Returns a task that when invoked, performs the given action
4320 <         * for each non-null transformation of each key
4320 >         * for each non-null transformation of each key.
4321           *
4322           * @param map the map
4323           * @param transformer a function returning the transformation
# Line 4328 | Line 4326 | public class ConcurrentHashMapV8<K, V>
4326           * @param action the action
4327           * @return the task
4328           */
4329 <        public static <K,V,U> ForkJoinTask<Void> forEachKey
4329 >        public static <K,V,U> ForkJoinTask<Void> forEachKey
4330              (ConcurrentHashMapV8<K,V> map,
4331               Fun<? super K, ? extends U> transformer,
4332               Action<U> action) {
# Line 4376 | Line 4374 | public class ConcurrentHashMapV8<K, V>
4374              return new ReduceKeysTask<K,V>
4375                  (map, reducer);
4376          }
4377 +
4378          /**
4379           * Returns a task that when invoked, returns the result of
4380           * accumulating the given transformation of all keys using the given
# Line 4472 | Line 4471 | public class ConcurrentHashMapV8<K, V>
4471  
4472          /**
4473           * Returns a task that when invoked, performs the given action
4474 <         * for each value
4474 >         * for each value.
4475           *
4476           * @param map the map
4477           * @param action the action
4478           */
4479 <        public static <K,V> ForkJoinTask<Void> forEachValue
4479 >        public static <K,V> ForkJoinTask<Void> forEachValue
4480              (ConcurrentHashMapV8<K,V> map,
4481               Action<V> action) {
4482              if (action == null) throw new NullPointerException();
# Line 4486 | Line 4485 | public class ConcurrentHashMapV8<K, V>
4485  
4486          /**
4487           * Returns a task that when invoked, performs the given action
4488 <         * for each non-null transformation of each value
4488 >         * for each non-null transformation of each value.
4489           *
4490           * @param map the map
4491           * @param transformer a function returning the transformation
# Line 4494 | Line 4493 | public class ConcurrentHashMapV8<K, V>
4493           * which case the action is not applied).
4494           * @param action the action
4495           */
4496 <        public static <K,V,U> ForkJoinTask<Void> forEachValue
4496 >        public static <K,V,U> ForkJoinTask<Void> forEachValue
4497              (ConcurrentHashMapV8<K,V> map,
4498               Fun<? super V, ? extends U> transformer,
4499               Action<U> action) {
# Line 4640 | Line 4639 | public class ConcurrentHashMapV8<K, V>
4639  
4640          /**
4641           * Returns a task that when invoked, perform the given action
4642 <         * for each entry
4642 >         * for each entry.
4643           *
4644           * @param map the map
4645           * @param action the action
4646           */
4647 <        public static <K,V> ForkJoinTask<Void> forEachEntry
4647 >        public static <K,V> ForkJoinTask<Void> forEachEntry
4648              (ConcurrentHashMapV8<K,V> map,
4649               Action<Map.Entry<K,V>> action) {
4650              if (action == null) throw new NullPointerException();
# Line 4654 | Line 4653 | public class ConcurrentHashMapV8<K, V>
4653  
4654          /**
4655           * Returns a task that when invoked, perform the given action
4656 <         * for each non-null transformation of each entry
4656 >         * for each non-null transformation of each entry.
4657           *
4658           * @param map the map
4659           * @param transformer a function returning the transformation
# Line 4662 | Line 4661 | public class ConcurrentHashMapV8<K, V>
4661           * which case the action is not applied).
4662           * @param action the action
4663           */
4664 <        public static <K,V,U> ForkJoinTask<Void> forEachEntry
4664 >        public static <K,V,U> ForkJoinTask<Void> forEachEntry
4665              (ConcurrentHashMapV8<K,V> map,
4666               Fun<Map.Entry<K,V>, ? extends U> transformer,
4667               Action<U> action) {
# Line 4811 | Line 4810 | public class ConcurrentHashMapV8<K, V>
4810  
4811      /**
4812       * Base for FJ tasks for bulk operations. This adds a variant of
4813 <     * CountedCompleters and some split and merge bookeeping to
4813 >     * CountedCompleters and some split and merge bookkeeping to
4814       * iterator functionality. The forEach and reduce methods are
4815       * similar to those illustrated in CountedCompleter documentation,
4816       * except that bottom-up reduction completions perform them within
# Line 4842 | Line 4841 | public class ConcurrentHashMapV8<K, V>
4841          // FJ methods
4842  
4843          /**
4844 <         * Propagate completion. Note that all reduce actions
4844 >         * Propagates completion. Note that all reduce actions
4845           * bypass this method to combine while completing.
4846           */
4847          final void tryComplete() {
# Line 4860 | Line 4859 | public class ConcurrentHashMapV8<K, V>
4859          }
4860  
4861          /**
4862 <         * Force root task to throw exception unless already complete.
4862 >         * Forces root task to throw exception unless already complete.
4863           */
4864          final void tryAbortComputation(Throwable ex) {
4865              for (BulkTask<K,V,?> a = this;;) {
# Line 4877 | Line 4876 | public class ConcurrentHashMapV8<K, V>
4876              try {
4877                  compute();
4878              }
4879 <            catch(Throwable ex) {
4879 >            catch (Throwable ex) {
4880                  tryAbortComputation(ex);
4881              }
4882              return false;
# Line 4893 | Line 4892 | public class ConcurrentHashMapV8<K, V>
4892          }
4893  
4894          /**
4895 <         * Return approx exp2 of the number of times (minus one) to
4895 >         * Returns approx exp2 of the number of times (minus one) to
4896           * split task by two before executing leaf action. This value
4897           * is faster to compute and more convenient to use as a guide
4898           * to splitting than is the depth, since it is used while
# Line 4904 | Line 4903 | public class ConcurrentHashMapV8<K, V>
4903              if (b < 0) {
4904                  long n = map.counter.sum();
4905                  int sp = getPool().getParallelism() << 3; // slack of 8
4906 <                b = batch = (n <= 0L)? 0 : (n < (long)sp) ? (int)n : sp;
4906 >                b = batch = (n <= 0L) ? 0 : (n < (long)sp) ? (int)n : sp;
4907              }
4908              return b;
4909          }
# Line 4916 | Line 4915 | public class ConcurrentHashMapV8<K, V>
4915              "Unexpected null function";
4916  
4917          /**
4918 <         * Return exportable snapshot entry
4918 >         * Returns exportable snapshot entry.
4919           */
4920          static <K,V> AbstractMap.SimpleEntry<K,V> entryFor(K k, V v) {
4921              return new AbstractMap.SimpleEntry(k, v);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines