Subject: libprop iterators
To: None <tech-kern@NetBSD.org>
From: Chapman Flack <nblists@anastigmatix.net>
List: tech-kern
Date: 06/06/2006 10:33:42
libprop iterators currently have the (reasonable) restriction that they
become invalid if a structure-changing operation (removal or insertion)
occurs on the underlying collection. Once the iterator is invalidated,
iteration has to restart at the beginning.

This, however, puts you in quadraticland if what you want to do is
iterate through a collection looking for things to remove. Or, you
can trade space for time and do it by selectively copying the
collection to a new one, or building a list of things to remove in
one pass, and then removing them.

Java provided for that use by giving each iterator a remove() method
that simply removes from the collection that most recent object the
iterator returned, and keeps that iterator synchronized. (Any other
active iterators are still invalidated, of course.)

Even if the collection is so small you don't care about the
performance, it still helps keep the code concise:

      while ( e = it.next() ) if ( e.isdead() ) it.remove();

is just nicer to read than any of the alternatives.

Would any object if I were to add such a method to libprop iterators?
It looks to take very few LOC.

-Chap