In message <20001002221632$[EMAIL PROTECTED]>
Uri Guttman <[EMAIL PROTECTED]> wrote:
> hmm, that means 'next' does a lookup based on the key passed
> in. currently next uses the iterator state which is much faster. i think
> next should be faster than a regular lookup but the semantics don't
> specify that. your idea still fails when the hash gets modified during
> iteration (does any iterator survive munging during iteration? other
> than full copies?)
It's possible to design an iterator such that it freezes state
by copying (possibly only on demand) but other than that it is
difficult to give guarantees that changing the data structure
won't damage active iterators.
Some data structures (eg balanced trees) are better than some
others (eg hash tables) in this regard but they all have prolems
with at least some changes.
I do agree with you though that having to do a lookup on the old
key for each next could be horribly expensive, especially for a
tied hash where you might have to do a database lookup or something.
> i agree. but we all seem to want better than we have now. i think
> stateful is good but probably only in external iterators. just having
> that will solve most of the iterator problems we see. munging during
> iteration is bad in general and should be forbidden.
>
> so to recap my previous letter, let's keep one stateful iterator
> attached to the hash, and support external (stateful?) iterators on
> demand. other than munging during iteration, IMO that solves most (%99+
> ?) of the iteration issues.
I fully agree that the current one iterator per hash situation is not
a major issue from the point of view of explicit iterator use by the
user, but I see iterators as a possible way of implementing many internal
things related to lazy evaluation and such like in an efficient way
so I think it's quite important to provide for a general system of
iterators with multiple iterators per data structure.
Tom
--
Tom Hughes ([EMAIL PROTECTED])
http://www.compton.nu/
...There is very little future in being right when your boss is wrong.