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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6c43f45c2ab47c51 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!news.netcologne.de!newsfeed-fusi2.netcologne.de!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Using Ada.Containers.Vector and Limited Private types Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8ff4c6c2-9892-463e-bdfd-1f7bfd78d607@s50g2000hsb.googlegroups.com> <4c5bfeb0-daa0-45e4-82f0-eebabda565e9@d45g2000hsc.googlegroups.com> Date: Sat, 12 Jul 2008 09:53:33 +0200 Message-ID: <86v8h7qx6nwr.1mso33mddoxpd.dlg@40tude.net> NNTP-Posting-Date: 12 Jul 2008 09:53:37 CEST NNTP-Posting-Host: de64b7aa.newsspool1.arcor-online.net X-Trace: DXC=@>;kLZ0O=3BI7\_^6>c20Jic==]BZ:afN4Fo<]lROoRA<`=YMgDjhgB^i`d^>^DLEA[6LHn;2LCVN[kNeEST?Yj@2<<1W?g65WH X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:1121 Date: 2008-07-12T09:53:37+02:00 List-Id: On Thu, 10 Jul 2008 15:59:30 -0700 (PDT), Gene wrote: > procedure List_By_Date is > > type String_Ptr_Type is access String; > type File_Info_Type is > record > Modification_Time : Time; > Simple_Name : String_Ptr_Type; -- Freed with storage pool! > end record; > > package File_Info_Vectors is > new Ada.Containers.Vectors (Positive, File_Info_Type); I am using a different design in such cases, which are a kind of cached data store with sorted items. I would make a descriptor type containing all data of an item: type File_Info (Length : Natural) is record Modification_Time : Time; Simple_Name : String (1..Length); ... end record; File_Info can be allocated in an arena or mark-and-release pool. That is no matter. Then comparison operations are defined on the pointers rather than the descriptors: type File_Info_By_Date is access all File_Info; function "<" (Left, Right : File_Info_By_Date) return Boolean; type File_Info_By_Name is access all File_Info; function "<" (Left, Right : File_Info_By_Name) return Boolean; type File_Info_By_Size is access all File_Info; function "<" (Left, Right : File_Info_By_Size) return Boolean; etc. Then I would create ordered sets of File_Info_By_Date, File_Info_By_Name and so on. All this I put into a controlled object which takes care about inserting and removing items. Indexes of pointers are kept sorted. This is exactly the design I used for a persistency layer. (I don't use Ada.Containers, but I think this approach should work with them too.) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de