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-Thread: 103376,5524603d74cda791 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Inter-object pointer problem References: <1147806613.377038.169250@j33g2000cwa.googlegroups.com> <2kqag.975795$xm3.614021@attbi_s21> <1147816421.575165.66310@j33g2000cwa.googlegroups.com> In-Reply-To: <1147816421.575165.66310@j33g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <9wvag.976205$xm3.459417@attbi_s21> NNTP-Posting-Host: 12.201.97.176 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1147831429 12.201.97.176 (Wed, 17 May 2006 02:03:49 GMT) NNTP-Posting-Date: Wed, 17 May 2006 02:03:49 GMT Date: Wed, 17 May 2006 02:03:49 GMT Xref: g2news2.google.com comp.lang.ada:4281 Date: 2006-05-17T02:03:49+00:00 List-Id: Alex Catlin wrote: > > I have a pairing heap package, I'm going to store a load of integers in > multiple pairing heaps. > I have a binary tree package, I want to store pointers to these > different heaps in the binary tree. The idea is that I can search > through the binary tree (sorted by key), and find out which heap the > Personal_Data is with that ID. Why pointers? Why not the heaps themselves? > with Ada.Text_IO, RB_Tree_Package, Pairing_Heap; > > package body Main is > > --The tree package needs a pointer to a heap datatype to be > instantiated > --One (obviously invalid) way would be to put > Pairing_Heap.Heap_Ptr in here. package Personal_Data_Heap is new Pairing_Heap (Personal_Data); -- I assume Personal_Data is visible, since you use it that way -- later. > package RB_Tree is new RB_Tree_Package(Key, *a pointer to a heap*); "Key" is undefined here, and later you want to use Integer for your key. package RB_Tree is new RB_Tree_Package (Integer, Personal_Data_Heap.Pairing_Heap); > Group_Tree : RB_Tree.Red_Black_Tree; > > --Create new heap, put Personal_Data in it, then put key field and > pointer to the > --new heap in tree. > procedure Process (Key : in Integer; > Data : in Integer) is > New_Entry : Personal_Data := (Key, Data); > package Heap is new Pairing_Heap (Personal_Data); > type Heap_Ptr is access Heap; Get rid of Heap and Heap_Ptr. Note you cannot have a pointer to a package. Heap : Personal_Data_Heap.Pairing_Heap; > begin > Ptr_To_Heap := Heap; > Heap.Insert(Heap,Personal_Data); > RB_Tree.Insert( T => Group_Tree, > Key => Key, > Content => Ptr_To_Heap); Nor can you pass a type (Personal_Data) to a procedure. Personal_Data_Heap.Insert (Main_Heap => Heap, D => New_Entry); RB_Tree.Insert (T => Group_Tree, Key => Key, Content => Heap); > end Process; > end Main; It would help to have the spec of Main. Note that you have exactly one pair in each heap, so why not simply store the pair in the tree and skip the heap altogether: package RB_Tree is new RB_Tree_Package (Integer, Personal_Data); ... RB_Tree.Insert (T => Group_Tree, Key => Key, Content => New_Entry); ? -- Jeff Carter "If you don't get the President of the United States on that phone, ... you're going to have to answer to the Coca-Cola Company." Dr. Strangelove 32