comp.lang.ada
 help / color / mirror / Atom feed
* File chicken counts eggs
@ 1997-05-07  0:00 Mark Kambites
  1997-05-08  0:00 ` Nick Roberts
  1997-05-08  0:00 ` Robert I. Eachus
  0 siblings, 2 replies; 3+ messages in thread
From: Mark Kambites @ 1997-05-07  0:00 UTC (permalink / raw)



Hello fellow Ada users!

I'm attempting to implement a B-tree-type structure on disk. This requires
that each node in the tree contains file indices, indicating where in the
file its children can be found. Such indices are implemented in Ada as the
'count' type which is declared in direct_io. Unfortunately, nothing in
direct_io is visible until direct_io has been instantiated, and I need
to instantiate it with my node as the generic type parameter. Have you
spotted the problem yet?

It seems that the size of my node must be known to the compiler before
direct_io can be instantiated, and the size of the node is dependant upon
the size of 'count', which is unknown UNTIL direct_io HAS BEEN instantiated.

Surely there must be a better way of handling this than trying to
effectively cast backwards and forwards between count and integer - exactly
the kind of thing Ada was designed to eliminate?

Any help much appreciated, espcially if its reasonably quick! :-)

   /\/)ark /-(ambites

------------------------------------------------------------------------------
 All opinions here expressed represent the views of either me when drunk or
 me when sober. The reader is granted absolute right to make a wild guess as
 to which is which. Hiccup.





--

   /\/)ark /-(ambites

------------------------------------------------------------------------------
 All opinions here expressed represent the views of either me when drunk or
 me when sober. The reader is granted absolute right to make a wild guess as
 to which is which. Hiccup.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: File chicken counts eggs
  1997-05-07  0:00 File chicken counts eggs Mark Kambites
@ 1997-05-08  0:00 ` Nick Roberts
  1997-05-08  0:00 ` Robert I. Eachus
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Roberts @ 1997-05-08  0:00 UTC (permalink / raw)





Mark Kambites <mek100@york.ac.uk> wrote in article
<5kqku3$bch$1@netty.york.ac.uk>...
> Hello fellow Ada users!
> 
> I'm attempting to implement a B-tree-type structure on disk. This
requires
> that each node in the tree contains file indices, indicating where in the
> file its children can be found. Such indices are implemented in Ada as
the
> 'count' type which is declared in direct_io. Unfortunately, nothing in
> direct_io is visible until direct_io has been instantiated, and I need
> to instantiate it with my node as the generic type parameter. Have you
> spotted the problem yet?
> 
> It seems that the size of my node must be known to the compiler before
> direct_io can be instantiated, and the size of the node is dependant upon
> the size of 'count', which is unknown UNTIL direct_io HAS BEEN
instantiated.


I think it is generally acknowledged that the COUNT type declared in
SEQUENTIAL_IO, DIRECT_IO, and TEXT_IO (in Ada 83) was a mistake. A
predefined integer type should have been used instead; among other things,
this would have obviated the problem you encounter.

Since you are (presumably) using multiple instantiations of DIRECT_IO, each
instantiation will give rise to a (nominally) different type COUNT. Thus,
you cannot avoid explicit type conversions.

Technically, given instantiations such as:

package FILE_1_IO is new DIRECT_IO(TYPE_1);
package FILE_2_IO is new DIRECT_IO(TYPE_2);
package FILE_3_IO is new DIRECT_IO(TYPE_3);

you should declare a new type:

type OVERALL_COUNT is range 0 .. MAX(MAX(FILE_1_IO.COUNT'LAST,
FILE_2_IO.COUNT'LAST), FILE_3_IO.COUNT'LAST);

where MIN and MAX are declared as appropriate.

However, this is so clumsy, you may want to simply declare OVERALL_COUNT as
0 .. SYSTEM.MAX_INT, or some other big range which works.

Either way, you will have to declare components of type OVERALL_COUNT in
your tree, and convert explicitly as required.

Nick.






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: File chicken counts eggs
  1997-05-07  0:00 File chicken counts eggs Mark Kambites
  1997-05-08  0:00 ` Nick Roberts
@ 1997-05-08  0:00 ` Robert I. Eachus
  1 sibling, 0 replies; 3+ messages in thread
From: Robert I. Eachus @ 1997-05-08  0:00 UTC (permalink / raw)



In article <5kqku3$bch$1@netty.york.ac.uk> mek100@york.ac.uk (Mark Kambites) writes:

  > It seems that the size of my node must be known to the compiler
  > before direct_io can be instantiated, and the size of the node is
  > dependant upon the size of 'count', which is unknown UNTIL
  > direct_io HAS BEEN instantiated.

  > Surely there must be a better way of handling this than trying to
  > effectively cast backwards and forwards between count and integer
  > -- exactly the kind of thing Ada was designed to eliminate?

  First, why is this seen as such a problem?  You can use Integer, a
type with a range you specify, or Unsigned_32 or whatever make sense
to you, and the file system gets to use a unit approprite for it's
purposes.  Using a system specific index size in your code would limit
portability.

  Since the conversions needed should all be in the body of your
B-tree package, I assume that the user of the package never has to
care.  You do, but the conversion only occur in a (very) few places,
right?

   If they don't define disk and internal data structures, one before
the Direct_IO instantiation, and one after.  Now write your own Get
and Put for the internal data structures, which do the mapping then
call the Direct_IO routines.  This should run to about ten lines of
code.  Now forget about those, and write the B-tree code.

   Secnnd, imagine that Direct_IO were defined to take Count as a type
parameter.  (You can experiment with this using the GNAT version.)
The specification change is trivial and the changes in the body will
probably take only an hour or two.  But are you, or anyone, happy with
the result?  You can't supply a default, which might acutally be
useful in this case, and if the user chooses a type too small, he gets
lots of errors with no discernable benefit.
--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-05-08  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-07  0:00 File chicken counts eggs Mark Kambites
1997-05-08  0:00 ` Nick Roberts
1997-05-08  0:00 ` Robert I. Eachus

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