ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] ingvard commented on a change in pull request #6536: IGNITE-6957 Boxing / Unboxing optimization - added IntSet.
Date Mon, 05 Aug 2019 09:36:11 GMT
ingvard commented on a change in pull request #6536: IGNITE-6957 Boxing / Unboxing optimization
- added IntSet.
URL: https://github.com/apache/ignite/pull/6536#discussion_r304472683
 
 

 ##########
 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;
             }
 
             /** {@inheritDoc} */
             @Override public Integer next() {
-                if (next == -1)
+                int nextIdx = bitSet.nextSetBit(idx + 1);
+
+                if (nextIdx == -1)
                     throw new NoSuchElementException();
 
-                return next;
+                idx = nextIdx;
+
+                return idx;
             }
         };
     }
 
-    /** Unsupported operation. */
+    /** {@inheritDoc} */
     @Override public boolean add(Integer integer) {
-        if (integer == null || integer < 0)
+        if (integer == null)
             throw new UnsupportedOperationException("Negative or null values are not supported!");
 
-        boolean alreadySet = bitSet.get(integer);
+        return add((int) integer);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean add(int element) {
+        if (element < 0)
+            throw new UnsupportedOperationException("Negative or null values are not supported!");
+
+        boolean alreadySet = bitSet.get(element);
 
         if (!alreadySet) {
-            bitSet.set(integer);
+            bitSet.set(element);
 
             size++;
 
 Review comment:
   return true ::  false

----------------------------------------------------------------
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