ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] ibessonov commented on a change in pull request #6536: IGNITE-6957 Boxing / Unboxing optimization - added IntSet.
Date Fri, 21 Jun 2019 13:57:27 GMT
ibessonov commented on a change in pull request #6536: IGNITE-6957 Boxing / Unboxing optimization
- added IntSet.
URL: https://github.com/apache/ignite/pull/6536#discussion_r295902570
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/util/collection/BitSetIntSet.java
 ##########
 @@ -61,79 +73,105 @@ public BitSetIntSet(int initCap) {
         if (o == null)
             throw new UnsupportedOperationException("Null values are not supported!");
 
-        int val = (int)o;
+        return contains((int)o);
+    }
 
-        if (val < 0)
+    /** {@inheritDoc} */
+    public boolean contains(int element) {
+        if (element < 0)
             throw new UnsupportedOperationException("Negative values are not supported!");
 
-        return bitSet.get(val);
+        return bitSet.get(element);
     }
 
     /** {@inheritDoc} */
     @NotNull @Override public Iterator<Integer> iterator() {
         return new Iterator<Integer>() {
-            private int next = -1;
+            /** */
+            private int idx = -1;
 
             /** {@inheritDoc} */
             @Override public boolean hasNext() {
-                int nextBit = bitSet.nextSetBit(next + 1);
-
-                if (nextBit != -1) {
-                    next = nextBit;
-
-                    return true;
-                }
-                else
-                    return false;
+                return bitSet.nextSetBit(idx + 1) != -1;
 
 Review comment:
   I suggest the optimization: store nextIdx in field after calculation. We can easily support
following invariant:
    - idx == nextIdx - "hasNext" hasn't been invoked or set is empty.
    - idx != nextIdx - "hasNext" has been invoked and set is not empty, "next" has not been
invoked (each "next" invocation will execute "nextIdx = idx = nextIdx").
   
   What do you think? It'll reduce number of array scans to 1 instead of 2.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message