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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1fa85f3df5841ae1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news2.google.com!proxad.net!usenet-fr.net!news.enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: Ada.Containers.Vectors - querying multiple elements Date: Tue, 26 Apr 2005 16:39:38 +0200 Organization: Cuivre, Argent, Or Message-ID: References: <426e4c2b$0$7515$9b4e6d93@newsread2.arcor-online.net> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1114526398 54337 212.85.156.195 (26 Apr 2005 14:39:58 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 26 Apr 2005 14:39:58 +0000 (UTC) Cc: comp.lang.ada@ada-france.org To: Georg Bauhaus Return-Path: In-Reply-To: <426e4c2b$0$7515$9b4e6d93@newsread2.arcor-online.net> X-Mailer: Evolution 2.2.1.1 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:10719 Date: 2005-04-26T16:39:38+02:00 Hi Georg, thanks for replying. > > procedure Query_Elements > > (Container : in Vector; > > First_Index : in Index_Type; > > Last_Index : in Extended_Index; > > Process : not null access procedure (Elements : in Element_Array)); > > > > It would be good to have for both > > efficiency reasons and simple implementation of certain classes of algorithms. > > In my case I have a "divide and conquer" recursive algorithm which while it > > can be written using the current package, would be simpler to write if something > > like Query_Elements existed. > > Couldn't you use Cursors, > > here: Cursor := find_or_something(container, ...); > there: constant Cursor := find_or_something(container, ...); > > while here /= there loop > ... > next(here); > end loop; I'm particularly concerned about: (1) efficiency - suppose (for example) I want to transmit the contents of my vector down a socket. Then I would have to do an element-by- element copy into a buffer (using code like you suggest), and then send the buffer. The element-by-element copy is inefficient, and with a procedure like Query_Elements above simply wouldn't (necessarily) be needed. An element-by-element copy can't compete with memcpy (what you'd probably get if you copied a slice directly, which would be possible using Query_Elements), and certainly can't compete with no copy at all. By the way, this is not a real example, it's just the first thing that came to mind. In any case, it is a special case of point (2): (2) reuse of legacy code - I don't know about you, but I've a lot of legacy code around that takes an array as a parameter. I mean code that doesn't change the length of the array (or anything like that) - code that just operates on the array in-place. Suppose I am using a Vector, and want to have some legacy code operate on it, or on part of it. Right now I would have to copy the appropriate part of the Vector into a buffer, and pass that to the legacy code, and then copy it back. Not very efficient - and not necessary if the Vectors api was extended slightly. Ciao, D.