Kris-10-0 commented on a change in pull request #7431: URL: https://github.com/apache/geode/pull/7431#discussion_r829461433
########## File path: geode-for-redis/src/main/java/org/apache/geode/redis/internal/data/collections/SizeableByteArrayList.java ########## @@ -31,6 +32,57 @@ roundUpSize(getObjectHeaderSize() + 3 * getReferenceSize()); private int memberOverhead; + /** + * @param o element to remove from the list + * @param count number of elements that match object o to remove from the list. + * Count that is equal to 0 removes all matching elements from the list. + * @return list of indexes that were removed in order. + */ + public List<Integer> remove(Object o, int count) { + if (0 <= count) { + count = count == 0 ? this.size() : count; + return removeObjectsStartingAtHead(o, count); + } else { + return removeObjectsStartingAtTail(o, -count); + } + } + + private List<Integer> removeObjectsStartingAtHead(Object o, int count) { + int index = 0; + ListIterator<byte[]> iterator = this.listIterator(index); + List<Integer> indexesRemoved = new LinkedList<>(); + + while (iterator.hasNext() && count != indexesRemoved.size()) { + byte[] element = iterator.next(); + if (Arrays.equals(element, (byte[]) o)) { + iterator.remove(); + memberOverhead -= calculateByteArrayOverhead(element); + indexesRemoved.add(index); + } + + index++; + } + return indexesRemoved; + } + + private List<Integer> removeObjectsStartingAtTail(Object o, int count) { + int index = this.size() - 1; + ListIterator<byte[]> descendingIterator = this.listIterator(this.size()); Review comment: I can use previousIndex() to keep track of the indexes when it starts at the tail. But I can't do it when it starts at the head. When it starts at the head, if I have a list a, b, c, d, the indexes get updated as I am removing elements. I.E. Using nextIndex() a -> index 0 b -> index 1 REMOVE B c -> index 1 REMOVE C d -> index 1 If I start at the tail the indexes don't get updated. I.E. Using previousIndex() d -> index 3 c -> index 2 REMOVE C b -> index 1 REMOVE B a -> index 0 Since I modified it to only have one delta type, the list of indexes needed to be formatted the same. I kept track of the indexes on both methods so they looked the same, but I can change it so I use previousIndex() on the one that starts from the tail. -- 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