comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: Inter-object pointer problem
Date: Wed, 17 May 2006 02:03:49 GMT
Date: 2006-05-17T02:03:49+00:00	[thread overview]
Message-ID: <9wvag.976205$xm3.459417@attbi_s21> (raw)
In-Reply-To: <1147816421.575165.66310@j33g2000cwa.googlegroups.com>

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



  parent reply	other threads:[~2006-05-17  2:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1147806613.377038.169250@j33g2000cwa.googlegroups.com>
2006-05-16 19:58 ` Inter-object pointer problem Georg Bauhaus
2006-05-16 20:09 ` Jeffrey R. Carter
     [not found]   ` <1147816421.575165.66310@j33g2000cwa.googlegroups.com>
2006-05-17  2:03     ` Jeffrey R. Carter [this message]
2006-05-16 20:27 ` Martin Dowie
replies disabled

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