From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7350da5176edec2c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-26 08:52:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: In a pickle. Date: 26 Jul 2002 11:43:15 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <3D3F0E27.9080303@worldnet.att.net> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1027698719 26279 128.183.220.71 (26 Jul 2002 15:51:59 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 26 Jul 2002 15:51:59 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:27421 Date: 2002-07-26T15:51:59+00:00 List-Id: "chris.danx" writes: > The task of implementing iterators is proving very difficult, can > anyone please offer some guidance/pointers? I've just put up my Grace.Lists implementation; see http://users.erols.com/leakstan/Stephe/index.html It does "safe" iterators; iterators are invalidated if the item they point to is deleted, etc. > I want operations on a node which would invalidate iterators to take > place only when one iterator references a node. For example deleting > a node should only occur when one, and only one iterator points to > it (if more than one iterator points to the node an exception should > occur). Grace does not require this. I guess you're doing something like "reference counting garbage collection". So Grace iterators are not exactly what you want. But there may be some implementation ideas you can use. > First I tried a scheme involving counting the number of iterators > that reference a node, but this approach lead to a very complex > implementation, so it's back to the drawing board. :( Complexity is sometimes necessary :). > One difficulty encountered is in signalling that we are done with a > node. Suppose the statement > > Iterator := Next (Iterator); > > is allowed. Prior to the call Iterator points to a node in the list > (if it did not Next would raise Invalid_Iterator_Error), which it will > leave after the assignment. The node needs to know an iterator has > left, but how? Finalize can decrement the counter but it's difficult > to control exactly when. Consider this... > > function Next (Iterator : in Iterator_Type) return Iterator_Type is > Temp : Iterator_Type; > begin > ... > return Temp; > end Next; > > After return Temp; Temp will be finalized so we need to record that > temp is just temporary. Then we have the problem of intelligently > adjusting the iterator on the left hand-side. :( Yes, using temporaries causes complexity. You might try using aggregates instead; that gives you more direct control over what's going on. Neither Initialize nor Finalize is called on an aggregate. > Now I know why John English skipped the issue in "ada: the craft..." > (I didn't fully appreciate Johns' warning on this) and why other > list implementations either skip the issue or are quite complex. Welcome to the club :). Implementing the Grace iterators was much more challenging than I thought it would be. And I haven't really tested it yet; that's more work than I want to do right now. > Is there a better solution to this problem??? Since I'm not sure what your real top level problem is, I can't say. Can you say more about why you want reference counted iterators? -- -- Stephe