Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Modula 3 > iterators on co...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 85 of 148
Post > Topic >>

iterators on complex data structures

by Henning Thielemann <iakd0@[EMAIL PROTECTED] > Feb 1, 2004 at 10:55 PM

It seems to be a quite popular solution
to traverse through a complex data set like
SortedTables or Lists by an iterator object:

BiList.T = OBJECT
           METHODS
             iterate(): Iterator;
           END;

Iterator = OBJECT
           METHODS
             next(VAR value: Value.T;): BOOLEAN;
           END;
..

It allows for a nice WHILE loop
if 'value' needs no further conversion
or NARROWing as REFANYs does:

WHILE it.next(v) DO
  ...
END;

But it also forces the user to traverse in one direction.
Independent of the implementation of the List data type
an iteration through the data set
will always require the creation of an Iterator object,
a small one, though.


What's about an alternative approach
where one can obtain a black box handle
for some node and ask for its successors:

Node <: REFANY;

BiList.T = OBJECT
           METHODS
             getFirst(): Node;
             getLast(): Node;
             getNext(n:Node;): Node;
             getPrev(n:Node;): Node;
             getValue(n:Node; VAR value: Value.T; );
           END;

?

'Node' can be a pointer to some internal data of the list
or some data allocated just for the iteration.
If a node has no successor,
getNext returns NIL.
This would allow for an efficient implementation
for some data structures and
gives more freedom to the user.

What are the pros and cons for this approach?
I think one should restrict to one of these approaches
to keep a class for a data structure compact.


Some earlier discussion:

http://groups.google.de/groups?hl=de&lr=&ie=UTF-8&oe=UTF-8&threadm=kidyb8rvgkz.fsf%40lasker.dc.teknowledge.com&rnum=1&prev=/groups%3Fq%3Dgroup:comp.lang.modula3%2Biterators%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Dkidyb8rvgkz.fsf%2540lasker.dc.teknowledge.com%26rnum%3D1




 1 Posts in Topic:
iterators on complex data structures
Henning Thielemann <ia  2004-02-01 22:55:47 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 5:55:02 CDT 2008.