in reply to Design thoughts: iterator invalidation

Given the wide variety of ways to use a hash, I'm not sure if it is even possible to cover 'most cases' instead of just the most common case.

My guess at a default case for inexperienced coders would be to iterate over the list of keys present at the start, and skip any that were prematurely deleted.

Personally, I don't think I'd trust the iterator after changing the hash, but I'd probably hope that it would iterate until there are zero keys in the hash that it has not yet returned.

I think a poll on the topic would be worthwhile.

  • Comment on Re: Design thoughts: iterator invalidation

Replies are listed 'Best First'.
Re^2: Design thoughts: iterator invalidation
by BrowserUk (Patriarch) on Feb 21, 2015 at 14:11 UTC
    Personally, I don't think I'd trust the iterator after changing the hash, but I'd probably hope that it would iterate until there are zero keys in the hash that it has not yet returned.

    There are two problems with that statement:

    1. How would you know that the hash had changed if the change(s) occur in (a) different thread(s).
    2. Remembering which keys have already been returned would impose a huge burden.

      Ditto: noticing that a new key had been added at a point preceding the current position of the iterator.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      I do agree that it would probably be terrible to actually implement, moreso with threads involved. It would just be convenient if it magically worked that way.