dschneider-pivotal commented on a change in pull request #7389:
URL: https://github.com/apache/geode/pull/7389#discussion_r815210408



##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/data/RedisList.java
##########
@@ -42,16 +45,65 @@ public RedisList() {
     this.elementList = new SizeableByteArrayList();
   }
 
+  /**
+   * @param start start index of desired elments
+   * @param stop stop index of desired elments
+   * @return list of elements in the range (inclusive).
+   */
+  public List<byte[]> lrange(int start, int stop) {
+    start = transformNegIndexToPosIndex(start);
+    stop = transformNegIndexToPosIndex(stop);
+
+    // Out of range negative index changes to 0
+    start = Math.max(0, start);
+
+    int elementSize = elementList.size();
+    if (start > stop || elementSize <= start) {
+      return Collections.emptyList();
+    }
+
+    // Out of range positive stop index changes to last index available
+    stop = elementSize <= stop ? elementSize - 1 : stop;
+
+    List<byte[]> result = new LinkedList<>();
+    int curIndex;
+
+    // Finds the shortest distance to access nodes in range
+    if (start <= elementSize - stop - 1) {
+      // Starts at head to access nodes at start index then iterates forwards
+      curIndex = 0;
+      ListIterator<byte[]> iterator = elementList.listIterator(curIndex);

Review comment:
       I think the code would be easier to understand if we passed "start" or 
"stop-1" to listIterator(index) and it would get rid of the if check on the 
loop.




-- 
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: notifications-unsubscr...@geode.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to