New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ListIterator that supports remove() #110
Comments
Original comment posted by jared.l.levy on 2008-12-13 at 12:10 AM Thanks for the contribution! When considering new functionality, my first question is how helpful it would be. |
Original comment posted by jim.andreou on 2008-12-13 at 12:56 AM I take for granted that: a) ListIterators per se are useful (Bloch would agree I And besides, the api cost is so minimal (merely an overloading of an existing method (Even that is not really required, in the case that even this cost is deemed as |
Original comment posted by kevinb9n on 2009-09-17 at 05:57 PM (No comment entered for this change.) Labels: |
Original comment posted by kevinb9n on 2009-09-17 at 06:02 PM (No comment entered for this change.) Labels: |
Original comment posted by kevinb@google.com on 2010-07-30 at 03:53 AM (No comment entered for this change.) Labels: - |
Original comment posted by fry@google.com on 2011-01-26 at 10:41 PM (No comment entered for this change.) Status: |
Original comment posted by kevinb@google.com on 2011-07-13 at 06:18 PM (No comment entered for this change.) Status: |
Original comment posted by fry@google.com on 2011-12-10 at 03:34 PM (No comment entered for this change.) Labels: |
Original comment posted by fry@google.com on 2012-02-16 at 07:17 PM (No comment entered for this change.) Status: |
Original comment posted by wasserman.louis on 2012-05-16 at 02:12 PM Lists.filter is in the Idea Graveyard, no? Why would we provide this, then? |
Original comment posted by jim.andreou on 2012-05-16 at 03:21 PM Sure, this can be closed, and save some maintenance (e.g. updating all these tags over the years!) Status: |
Original comment posted by cpovirk@google.com on 2012-05-16 at 04:09 PM Graveyard says: "The biggest concern here is that too many operations become expensive, linear-time propositions." I think that this meant things like List.get. I suppose that it's technically true here, too, in the case of ListIterator.remove, but the same was true of Iterables.filter's hasNext/next calls, and that didn't stop us from providing that. Still, given that Dimitris is fine with closing this, I'm fine with it. |
Original issue created by jim.andreou on 2008-12-12 at 11:16 PM
Hi,
Some days ago I exchanged some emails on the list regarding the possibility
of a ListIterator that supported remove(). I contribute such an
implementation, which skips filtered elements bidirectionally to support
hasNext()/next() and hasPrevious()/previous().
It would be neat to have in Iterators a signature of the form:
ListIterator<E> filtered(ListIterator<E> listIterator, Predicate<? super E>
filter);
Thus an API can provide filtered ListIterators to internal structures
without having to clumsily work around the difficult-to-support remove()
issue. I believe the cost of a single iteration with removals does not, in
the worst case, cost more than O(3n), which should be optimal. In any case,
this is intended to fill a functional gap.
I'm also quite confident about its robustness. I tested it to filter a
ArrayList's ListIterator, for more than half million random actions
(comprising all methods defined by ListIterator), side-by-side with a
ListIterator of ArrayList which only contains accepted elements, and
verified that they both behave identically (i.e. one can't tell whether the
list is filtered or is just contains only the correct elements). I also
submit my (unpolished) test code for verification.
Note that ListIterator#add(E e) is curiously defined in a filtered iterator.
For example, in this list:
[A1, R2, R3, R4, A5](where A1, A5 are), and
a filtered iterator being between A1 and A5 (the client won't see R2-R4),
an add() operation surely does insert an element between A1 and A5 as
defined by the contract, but the exact place in the underlying list is not
specified. (In this implementation it will be either immediately before A5,
or immediately after A1)
Comments?
Thanks,
Dimitris
The text was updated successfully, but these errors were encountered: