Invalidating iterator

Rated 3.84/5 based on 797 customer reviews

Even though this is modifying the collection, I can't imagine an implementation where modifying a single element (assuming m1 !

= m2) actually invalidates the outer loop's iterator.

If you have to use Linked List I would do it like you did in your second example.

It has n complexity, but at least it's not exponential.

invalidating iterator-76

invalidating iterator-67

invalidating iterator-84

invalidating iterator-57

For memory reasons (as we often have thousands of cubes, each with hundreds of inputs), they use a custom collection implementation where each entry uses 2 bits in a vector of longs (very similar to the Java Bit Set implementation).

I'm not sure if Java allows collections to store 'null', but assuming that's permitted, a fourth alternative would be to use list Iterator.set(null); instead of actually removing the element, and then going through the list again and actually removing all the "nulls".

While still requiring a second traversal through the list, it does not require maintaining extra data structures.

A is true for the inputs 01 and 11, while B is true for 11, and C for 00.

This means that (A, B) fulfills the condition since A contains all true inputs of B, therefore B is superfluous and can be deleted.

Leave a Reply