ringles commented on a change in pull request #6715:
URL: https://github.com/apache/geode/pull/6715#discussion_r686266650



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/data/RedisSortedSet.java
##########
@@ -381,6 +381,55 @@ long zrem(Region<RedisKey, RedisData> region, RedisKey 
key, List<byte[]> members
     return getRange(min, max, withScores, true);
   }
 
+  List<byte[]> zrevrangebyscore(SortedSetScoreRangeOptions rangeOptions, 
boolean withScores) {
+    AbstractOrderedSetEntry maxEntry =
+        new ScoreDummyOrderedSetEntry(rangeOptions.getStartRange(), 
rangeOptions.isStartExclusive(),
+            false);
+    int maxIndex = scoreSet.indexOf(maxEntry);
+
+    AbstractOrderedSetEntry minEntry =
+        new ScoreDummyOrderedSetEntry(rangeOptions.getEndRange(), 
rangeOptions.isEndExclusive(),
+            true);
+    int minIndex = scoreSet.indexOf(minEntry);
+    if (minIndex > getSortedSetSize()) {
+      return Collections.emptyList();
+    }
+
+    if (minIndex == maxIndex) {
+      return Collections.emptyList();
+    }
+
+    // Okay, if we make it this far there's a potential range of things to 
return.
+    int count = Integer.MAX_VALUE;
+    if (rangeOptions.hasLimit()) {
+      count = rangeOptions.getCount();
+      maxIndex -= rangeOptions.getOffset();
+      if (maxIndex < 0) {
+        return Collections.emptyList();
+      }
+    }
+
+    int startIndex = maxIndex - 1;
+    int endIndex = Math.min(count, maxIndex - minIndex);
+    int initialCapacity = startIndex - endIndex;
+    if (withScores) {
+      initialCapacity *= 2;
+    }
+
+    Iterator<AbstractOrderedSetEntry> entryIterator =
+        scoreSet.getIndexRange(startIndex, endIndex, true);
+    List<byte[]> result = new ArrayList<>(initialCapacity > 0 ? 
initialCapacity : 0);

Review comment:
       Yeah, per Donal we're using the addLimitToRange (with some tweaks now).

##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/executor/sortedset/AbstractSortedSetRangeOptions.java
##########
@@ -66,26 +66,31 @@ void parseLimitArguments(List<byte[]> commandElements, int 
commandIndex) {
 
   // If limit specified but count is zero, or min > max, or min == max and 
either are exclusive, the
   // range cannot contain any elements
-  boolean isEmptyRange() {
-    int minVsMax = compareMinToMax();
-    return (hasLimit && (count == 0 || offset < 0)) || minVsMax == 1
-        || (minVsMax == 0 && (isMinExclusive || isMaxExclusive));
+  boolean isEmptyRange(boolean isRev) {
+    int startVsEnd = compareStartToEnd();

Review comment:
       Adjusted the code, and the leading comment to match the test order.




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