How stable are Mapping.Iterator and Multiset.Iterator? Is the order guaranteed, platform dependent or something else?
Well.
I think that is sort of the wrong question, what do you really want?
But:
As long as you have a multiset (and, in 8.0+ probably mapping) and do not change it's content the iteration order tends to be stable (modulo gc of destructed things in said containers in this case, or if they have weak marked values/indices as applicable, although I guess that could count as modifying them).
Mulisets are tree-order, but for some things it's pointer-address, for some it's `< on the value (aka, int and float). You can also write a `< operatoror that returns random(2) for great justice when comparing objects..
When you insert new things the order will of course change, since a new thing is there (same goes for removing items).
So, more or less: Multisets are stable, unless modified, as long as the process is running. If it's a multiset of ints (or possibly floats) the order is always the same, for all pikes.
Mappings are a hashtable, and the iteration is done in hash-table-bucket-order. As such, whenever they are modified things can move around.
It used to be that just indexing the mapping changed the order (the found item was moved to the top of the hash chain of it's bucket), I am not sure what the current status of that performance killing abomination is. :)
Also note: as long as the iterator is live it has a reference to the original mapping/multiset data, so "normal" changes (insert/remove item) should not cause a modification of the thing the iterator is looping over, instead a new copy will be created.
Note, however, that the fun move-to-head-when-indexing thing did not bother to check for writable mapping data, at least in 7.8. :)
Well, I guess my question is if _random on those iterators makes sense? And if so, if the test cases should have an explicit order of things?
Well. If random(container) works it might sense to have it works for iterators as well. But then again, how often is random used on iterators at all?
pike-devel@lists.lysator.liu.se