Not really. If you have an unordered set you might get two iterators that iterates over all members in different order.
/ Martin Nilsson (Fake Build Master)
Previous text:
2002-11-02 22:56: Subject: Re: Proposal for new ADT interface
Ok. Good point. Come to think about it, iterators in ordered collections ought to have `< and `> too.
Shouldn't all iterators? An iterator is by definition doing something ordered, isn't it...?
/ Brevbäraren
What if you'd want to write code like
foo(collection c) { iterator i, j;
for (i = c->start(), j = j->end(); i<j; i++, j++) do_something_interesting(); // ^ iterator comparison }
I think there should be some way to do that for any collection, ordered or not. It may do unexpected things if do_something_interesting() makes changes to the collection (that's a general problem I'm not sure how it is best solved), but it should degrade in an ordered fasshion, e.g. it shouldn't turn into an infinite loop.
/ Niels Möller ()
Previous text:
2002-11-02 23:11: Subject: Re: Proposal for new ADT interface
Not really. If you have an unordered set you might get two iterators that iterates over all members in different order.
/ Martin Nilsson (Fake Build Master)
In mappings it's solved by locking the index part; any modification that affects an index causes a copy to be made and the iterator(s) continue to use an otherwise unreferenced copy.
The problem with `< and `> on unordered collections is afaics mainly that it can be difficult to determine the relation between the two iterators. It might only be possible by stepping element by element from one of them to see if the other is encountered or not. The operation could still be useful, but it might be better to give it another name to avoid inadvertent misuse.
/ Martin Stjernholm, Roxen IS
Previous text:
2002-11-02 23:25: Subject: Re: Proposal for new ADT interface
What if you'd want to write code like
foo(collection c) { iterator i, j;
for (i = c->start(), j = j->end(); i<j; i++, j++) do_something_interesting(); // ^ iterator comparison }
I think there should be some way to do that for any collection, ordered or not. It may do unexpected things if do_something_interesting() makes changes to the collection (that's a general problem I'm not sure how it is best solved), but it should degrade in an ordered fasshion, e.g. it shouldn't turn into an infinite loop.
/ Niels Möller ()
If
1. the underlying collection is unmodified, and 2. the size of the collection is known
then it should be easy to associate an integer with each of the iterators. And comparison will do the right thing, if both iterators order the collection in a consistent way.
/ Niels Möller ()
Previous text:
2002-11-02 23:58: Subject: Re: Proposal for new ADT interface
In mappings it's solved by locking the index part; any modification that affects an index causes a copy to be made and the iterator(s) continue to use an otherwise unreferenced copy.
The problem with `< and `> on unordered collections is afaics mainly that it can be difficult to determine the relation between the two iterators. It might only be possible by stepping element by element from one of them to see if the other is encountered or not. The operation could still be useful, but it might be better to give it another name to avoid inadvertent misuse.
/ Martin Stjernholm, Roxen IS
That's a thought, but it only works if the iterator starts at either end, not if it's created using lookup with a key. Seems like the proper design is to have both ordered and unordered iterators, and then look at each iterator creating operation individually to see whether it can return an ordered iterator or not.
/ Martin Stjernholm, Roxen IS
Previous text:
2002-11-03 00:18: Subject: Re: Proposal for new ADT interface
If
- the underlying collection is unmodified, and
- the size of the collection is known
then it should be easy to associate an integer with each of the iterators. And comparison will do the right thing, if both iterators order the collection in a consistent way.
/ Niels Möller ()
You still have the possibillity to use (i != j) on an unordered iterator to avoid infinite loops
/ Peta, jo det är jag
Previous text:
2002-11-02 23:25: Subject: Re: Proposal for new ADT interface
What if you'd want to write code like
foo(collection c) { iterator i, j;
for (i = c->start(), j = j->end(); i<j; i++, j++) do_something_interesting(); // ^ iterator comparison }
I think there should be some way to do that for any collection, ordered or not. It may do unexpected things if do_something_interesting() makes changes to the collection (that's a general problem I'm not sure how it is best solved), but it should degrade in an ordered fasshion, e.g. it shouldn't turn into an infinite loop.
/ Niels Möller ()
What if you'd want to write code like
foo(collection c) { iterator i, j;
for (i = c->start(), j = j->end(); i<j; i++, j++) do_something_interesting(); // ^ iterator comparison }
I think there should be some way to do that for any collection, ordered or not. It may do unexpected things if do_something_interesting() makes changes to the collection (that's a general problem I'm not sure how it is best solved), but it should degrade in an ordered fasshion, e.g. it shouldn't turn into an infinite loop.
/ Niels Möller ()
Previous text:
2002-11-02 23:11: Subject: Re: Proposal for new ADT interface
Not really. If you have an unordered set you might get two iterators that iterates over all members in different order.
/ Martin Nilsson (Fake Build Master)
pike-devel@lists.lysator.liu.se