comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthewjheaney@earthlink.net>
Subject: Re: Adding functions to generic package
Date: Sun, 29 May 2005 22:27:45 GMT
Date: 2005-05-29T22:27:45+00:00	[thread overview]
Message-ID: <ud5r9zmzj.fsf@earthlink.net> (raw)
In-Reply-To: 429a34bc$1@news.broadpark.no

Preben Randhol <randhol+valid_for_reply_from_news@pvv.org> writes:

> I have two different questions. How can one splice an element to the end
> of the list? 

Just splice the element prior to the distinguished iterator value Back:

C : Container_Type;

procedure Op (I : Iterator_Type) is
begin
   Splice (C, Before => Back (C), Iterator => I);
end;

Back is the iterator that designates the virtual element
one-beyond-the-end of the list.


> Mustn't one then Append it and Delete or call Splice twice; first
> moving the element to the second last place and then move the last
> place in front of it?

No; just splice the element to the position before Back.  See above.


> Reading the source code I find that the Splice function can only
> splice an element before a given position.

Yes.  But if you splice an element before Back, that's the same as
appending it.


> Another question. Why isn't there a Swap function in the library like
> the one that you have in the Reverse_Container? I can make something
> using two splices although a bit less effective I should imagine?

Hmmm, not sure what you're asking for.  Swap exchanges the internal
linked lists of a pair of list containers.  Reverse_Container reverses
the nodes on the internal linked lists of a single list container.

The list container has both of the these operations, so what operation
do you need, that you want to implement using splice?

Thinking about it more, I think that what you're asking for is an
operation to swap a pair of nodes in the list, a la the Swap_Links
operation in the Ada 200Y container library.  I can add that operation,
if that's what you need.  (I just need to make sure I understand your
request.)

Note that I would probably just implement it using Splice.  That's what
I did in the standard container library reference implementation.

-Matt



      parent reply	other threads:[~2005-05-29 22:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-28 15:44 Adding functions to generic package Preben Randhol
2005-05-28 16:27 ` Matthew Heaney
2005-05-28 18:18   ` Preben Randhol
2005-05-28 18:20     ` Preben Randhol
2005-05-29  0:56     ` Matthew Heaney
2005-05-29  8:41       ` Preben Randhol
2005-05-29 14:37         ` Matthew Heaney
2005-05-29 21:31           ` Preben Randhol
2005-05-29 21:33             ` Preben Randhol
2005-05-29 22:30               ` Matthew Heaney
2005-05-30 20:45                 ` Preben Randhol
2005-05-30 22:28                   ` Marius Amado Alves
2005-06-01  1:50                     ` Matthew Heaney
2005-06-02 12:49                       ` Marius Amado Alves
2005-06-02 13:11                         ` Matthew Heaney
2005-06-01  1:41                   ` Matthew Heaney
2005-05-29 22:27             ` Matthew Heaney [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox