jdeppe-pivotal commented on a change in pull request #7236:
URL: https://github.com/apache/geode/pull/7236#discussion_r778403170



##########
File path: 
geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/set/AbstractSInterIntegrationTest.java
##########
@@ -60,9 +64,9 @@ public void sinterstoreErrors_givenTooFewArguments() {
   }
 
   @Test
-  public void testSInter() {
-    String[] firstSet = new String[] {"pear", "apple", "plum", "orange", 
"peach"};
-    String[] secondSet = new String[] {"apple", "microsoft", "linux", "peach"};
+  public void testSInter_givenIntersection_returnsIntersectedMembers() {
+    String[] firstSet = new String[] {"peach"};
+    String[] secondSet = new String[] {"linux", "peach"};

Review comment:
       Please could you restore at least the `"apple"` entry so that there is a 
partial intersection.

##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSet.java
##########
@@ -110,6 +111,47 @@ private static MemberSet calculateDiff(RegionProvider 
regionProvider, List<Redis
     return diff;
   }
 
+  public static Set<byte[]> sinter(RegionProvider regionProvider, 
List<RedisKey> keys) {
+    MemberSet result = calculateInter(regionProvider, keys);
+    if (result == null) {
+      return Collections.emptySet();
+    }
+    return result;
+  }
+
+  private static MemberSet calculateInter(RegionProvider regionProvider, 
List<RedisKey> keys) {
+    List<RedisSet> sets = new ArrayList<>(keys.size());
+    RedisSet smallestSet = null;
+
+    for (RedisKey key : keys) {
+      RedisSet redisSet = regionProvider.getTypedRedisData(REDIS_SET, key, 
true);
+      if (redisSet == NULL_REDIS_SET || redisSet.scard() == 0) {
+        return null;
+      } else {
+        if (smallestSet == null || smallestSet.scard() > redisSet.scard()) {
+          smallestSet = redisSet;
+        }
+        sets.add(redisSet);
+      }
+    }
+
+    MemberSet result = new MemberSet(smallestSet.scard());
+    for (byte[] member : smallestSet.members) {
+      boolean addToSet = true;
+      for (int i = 0; i < sets.size(); i++) {
+        RedisSet otherSet = sets.get(i);

Review comment:
       This could be simplified to:
   ```
         for (RedisSet otherSet : sets) {
   ```




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to