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_r295905681
 
 

 ##########
 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++;
         }
 
         return !alreadySet;
     }
 
-    /** Unsupported operation. */
+    /** {@inheritDoc} */
     @Override public boolean remove(Object o) {
         if (o == null)
             throw new UnsupportedOperationException("Null values are not supported!");
 
-        int val = (int)o;
+        return remove((int)o);
+    }
 
-        if (val < 0)
+    /** {@inheritDoc} */
+    @Override public boolean remove(int element) {
+        if (element < 0)
             throw new UnsupportedOperationException("Negative values are not supported!");
 
 Review comment:
   Return "false" here as well.

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