comp.lang.ada
 help / color / mirror / Atom feed
* Generic Containers in Ada2005
@ 2011-02-09  0:43 Bryan
  2011-02-09  0:57 ` Jeffrey Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Bryan @ 2011-02-09  0:43 UTC (permalink / raw)


I'm been writing a small Ada program for a personal project.  I
usually write C++/STL for such projects due to my background, but
because I wanted to get more practice with Ada, I decided to do the
project with Ada.  All has been well, except that I've been a bit
surprised about generic containers.

I was looking for a simple queue data structure, but I noticed there
is not a standard Queue container.  I managed to make a Vector work
like a Queue, but it feels a bit awkward:  Append() for a "push" and
First_Element()+Delete_First() for a "pop".  I realize that I can
write a wrapper interface and create my own queue, but queues are so
common I can't believe we have Hashed_Maps and not a simple Queue
container.

I'm just curious what the reasoning was behind not providing a Queue
container?  Is there some Ada philosophy behind this?  Or is there
something similar to the C++ Standard Template Library in Ada?




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

* Re: Generic Containers in Ada2005
  2011-02-09  0:43 Generic Containers in Ada2005 Bryan
@ 2011-02-09  0:57 ` Jeffrey Carter
  2011-02-09  1:26   ` Anh Vo
  2011-02-09  8:33 ` Dmitry A. Kazakov
  2011-02-10  2:03 ` Randy Brukardt
  2 siblings, 1 reply; 12+ messages in thread
From: Jeffrey Carter @ 2011-02-09  0:57 UTC (permalink / raw)


On 02/08/2011 05:43 PM, Bryan wrote:
>
> I realize that I can write a wrapper interface and create my own queue, but
> queues are so common I can't believe we have Hashed_Maps and not a simple
> Queue container.

I agree. And given that the Ada philosophy was usually to provide building 
blocks that the user can combine to create more complex things, it always 
surprised me that the library, when it finally came into existence, requires the 
implementor to have implementations of hash tables and an O(log N) searchable 
structure, but not to make them available to the user. (Of course, implementors 
have always had to have unlimited-precision math libraries, but not make them 
available.)

Personally, I'd base a queue on the lists package rather than the vectors.

You can find queues, as well as bounded data structures in the PragmAda Reusable 
Components:

http://pragmada.x10hosting.com/pragmarc.htm

-- 
Jeff Carter
"Mr. President, we must not allow a mine-shaft gap!"
Dr. Strangelove
33



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

* Re: Generic Containers in Ada2005
  2011-02-09  0:57 ` Jeffrey Carter
@ 2011-02-09  1:26   ` Anh Vo
  2011-02-09 10:56     ` Simon Wright
  0 siblings, 1 reply; 12+ messages in thread
From: Anh Vo @ 2011-02-09  1:26 UTC (permalink / raw)


On Feb 8, 4:57 pm, Jeffrey Carter <spam.jrcarter....@spam.not.acm.org>
wrote:
> On 02/08/2011 05:43 PM, Bryan wrote:
>
>
>
> > I realize that I can write a wrapper interface and create my own queue, but
> > queues are so common I can't believe we have Hashed_Maps and not a simple
> > Queue container.
>
> I agree. And given that the Ada philosophy was usually to provide building
> blocks that the user can combine to create more complex things, it always
> surprised me that the library, when it finally came into existence, requires the
> implementor to have implementations of hash tables and an O(log N) searchable
> structure, but not to make them available to the user. (Of course, implementors
> have always had to have unlimited-precision math libraries, but not make them
> available.)
>
> Personally, I'd base a queue on the lists package rather than the vectors.
>
> You can find queues, as well as bounded data structures in the PragmAda Reusable
> Components:
>
> http://pragmada.x10hosting.com/pragmarc.htm

Or look at http://www.adaic.org/ada-resources/tools-libraries/ for
Booch components and Charles (Charles Container Library). Although,
Ada 95 is the target, Booch components should be compatible with Ada
2005.

A. Vo



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

* Re: Generic Containers in Ada2005
  2011-02-09  0:43 Generic Containers in Ada2005 Bryan
  2011-02-09  0:57 ` Jeffrey Carter
@ 2011-02-09  8:33 ` Dmitry A. Kazakov
  2011-02-09 16:01   ` Bryan
  2011-02-09 20:56   ` Maciej Sobczak
  2011-02-10  2:03 ` Randy Brukardt
  2 siblings, 2 replies; 12+ messages in thread
From: Dmitry A. Kazakov @ 2011-02-09  8:33 UTC (permalink / raw)


On Tue, 8 Feb 2011 16:43:49 -0800 (PST), Bryan wrote:

> I'm just curious what the reasoning was behind not providing a Queue
> container?  Is there some Ada philosophy behind this?

I think that queue is a too specific container to be included into standard
library. Depending on the number of concurrent peers accessing the queue
ends, whether the queue has fixed size, whether elements are copied or
referenced (e.g. statically allocated elements moved from queue to queue)
the implementation and interface may sufficiently vary.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Generic Containers in Ada2005
  2011-02-09  1:26   ` Anh Vo
@ 2011-02-09 10:56     ` Simon Wright
  0 siblings, 0 replies; 12+ messages in thread
From: Simon Wright @ 2011-02-09 10:56 UTC (permalink / raw)


Anh Vo <anhvofrcaus@gmail.com> writes:

> Or look at http://www.adaic.org/ada-resources/tools-libraries/ for
> Booch components and Charles (Charles Container Library). Although,
> Ada 95 is the target, Booch components should be compatible with Ada
> 2005.

If you find a case where the BC's aren't compatible with Ada 2005 (read,
modern GNATs in -gnat05 mode!) please report a bug at
http://sourceforge.net/tracker/?group_id=135616&atid=733923 .



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

* Re: Generic Containers in Ada2005
  2011-02-09  8:33 ` Dmitry A. Kazakov
@ 2011-02-09 16:01   ` Bryan
  2011-02-09 19:10     ` Jeffrey Carter
  2011-02-09 20:06     ` Simon Wright
  2011-02-09 20:56   ` Maciej Sobczak
  1 sibling, 2 replies; 12+ messages in thread
From: Bryan @ 2011-02-09 16:01 UTC (permalink / raw)


Thanks for the links to the external libraries, I've downloaded the
Booch Components, but I'm not sure how to build and install the
library.  Is there an installation guide that goes over the necessary
environment variables and steps?  Just running running make does not
work, and I'm not sure what to do with gnat-booch.sh and gnat-
booch.conf.

On Feb 9, 3:33 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> I think that queue is a too specific container to be included into standard
> library. Depending on the number of concurrent peers accessing the queue
> ends, whether the queue has fixed size, whether elements are copied or
> referenced (e.g. statically allocated elements moved from queue to queue)
> the implementation and interface may sufficiently vary.

Regarding concurrent peers, are the generic containers provided in the
Ada.Containers library thread-safe?



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

* Re: Generic Containers in Ada2005
  2011-02-09 16:01   ` Bryan
@ 2011-02-09 19:10     ` Jeffrey Carter
  2011-02-09 20:06     ` Simon Wright
  1 sibling, 0 replies; 12+ messages in thread
From: Jeffrey Carter @ 2011-02-09 19:10 UTC (permalink / raw)


On 02/09/2011 09:01 AM, Bryan wrote:
>
> Regarding concurrent peers, are the generic containers provided in the
> Ada.Containers library thread-safe?

No. You can safely access different container objects from different tasks at 
the same time, but not concurrent access to the same object from different tasks.

-- 
Jeff Carter
"Sir Robin the not-quite-so-brave-as-Sir-Lancelot,
who had nearly fought the Dragon of Angnor,
who nearly stood up to the vicious Chicken of Bristol,
and who had personally wet himself at the
Battle of Badon Hill."
Monty Python & the Holy Grail
68



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

* Re: Generic Containers in Ada2005
  2011-02-09 16:01   ` Bryan
  2011-02-09 19:10     ` Jeffrey Carter
@ 2011-02-09 20:06     ` Simon Wright
  1 sibling, 0 replies; 12+ messages in thread
From: Simon Wright @ 2011-02-09 20:06 UTC (permalink / raw)


Bryan <brobinson.eng@gmail.com> writes:

> Thanks for the links to the external libraries, I've downloaded the
> Booch Components, but I'm not sure how to build and install the
> library.  Is there an installation guide that goes over the necessary
> environment variables and steps?  Just running running make does not
> work, and I'm not sure what to do with gnat-booch.sh and gnat-
> booch.conf.

Oh dear. After all this time & I haven't thought of it from a new user's
point of view. I've logged a bug report and assigned it to myself.

I don't understand the gnat-booch.sh &c setup myself, that was Martin
Krischik's work.

The simplest way ahead from what you have (if you're using GNAT) is to
include the BCs in the source path for your build - eg,

   $ gnatmake -gnat05 -I$HOME/bc-20090226/src foo.adb

If you're already using GPRs, or if you're not using GNAT, include the
sources (bc-yyyymmdd/src/*.ad?) in your compilation source path.

> On Feb 9, 3:33 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> I think that queue is a too specific container to be included into
>> standard library. Depending on the number of concurrent peers
>> accessing the queue ends, whether the queue has fixed size, whether
>> elements are copied or referenced (e.g. statically allocated elements
>> moved from queue to queue) the implementation and interface may
>> sufficiently vary.
>
> Regarding concurrent peers, are the generic containers provided in the
> Ada.Containers library thread-safe?

No. Nor are the BCs. I believe that the Ada2012 effort includes
synchronised queues (though the last I heard there was a serious
problem).

Personally I think Dmitry is right. Nothing to stop you using
non-thread-safe containers as part of the implementation of somethin
appropriate to your problem.



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

* Re: Generic Containers in Ada2005
  2011-02-09  8:33 ` Dmitry A. Kazakov
  2011-02-09 16:01   ` Bryan
@ 2011-02-09 20:56   ` Maciej Sobczak
  2011-02-09 21:22     ` Dmitry A. Kazakov
  1 sibling, 1 reply; 12+ messages in thread
From: Maciej Sobczak @ 2011-02-09 20:56 UTC (permalink / raw)


On Feb 9, 9:33 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:

> Depending on the number of concurrent peers accessing the queue
> ends, whether the queue has fixed size, whether elements are copied or
> referenced (e.g. statically allocated elements moved from queue to queue)
> the implementation and interface may sufficiently vary.

Exactly the same questions can be asked with regard to vectors.
Yet, we do have vectors in the standard library.

This means that the above concerns, even though perfectly valid, do
not explain the absence of queue in the library. The authors might
have done exactly the same as they did with vectors - give arbitrary
(but reasonable) answers to these questions and provide the solution
that fits the bill in the typical case.

--
Maciej Sobczak * http://www.inspirel.com



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

* Re: Generic Containers in Ada2005
  2011-02-09 20:56   ` Maciej Sobczak
@ 2011-02-09 21:22     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 12+ messages in thread
From: Dmitry A. Kazakov @ 2011-02-09 21:22 UTC (permalink / raw)


On Wed, 9 Feb 2011 12:56:05 -0800 (PST), Maciej Sobczak wrote:

> On Feb 9, 9:33�am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
>> Depending on the number of concurrent peers accessing the queue
>> ends, whether the queue has fixed size, whether elements are copied or
>> referenced (e.g. statically allocated elements moved from queue to queue)
>> the implementation and interface may sufficiently vary.
> 
> Exactly the same questions can be asked with regard to vectors.

Not really. Vectors are used for general purpose programming, queues
largely are for systems programming. You have less people who would demand
queues and their requirements would contradict each other.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Generic Containers in Ada2005
  2011-02-09  0:43 Generic Containers in Ada2005 Bryan
  2011-02-09  0:57 ` Jeffrey Carter
  2011-02-09  8:33 ` Dmitry A. Kazakov
@ 2011-02-10  2:03 ` Randy Brukardt
  2011-02-11  7:08   ` Stephen Leake
  2 siblings, 1 reply; 12+ messages in thread
From: Randy Brukardt @ 2011-02-10  2:03 UTC (permalink / raw)


"Bryan" <brobinson.eng@gmail.com> wrote in message 
news:d066a30c-b356-4b28-b713-764c2b895022@d17g2000vbn.googlegroups.com...
...
> I was looking for a simple queue data structure, but I noticed there
> is not a standard Queue container.

This is added by Ada 2012. See the latest draft of the Ada 2012 standard for 
details:
http://www.ada-auth.org/standards/12rm/html/RM-A-18-27.html
(and the next 5 clauses as well).

As to exactly when your favorite Ada compiler adds this container, you'd 
have to ask them. (I believe some versions of GNAT already have versions of 
this container.)

                                    Randy.






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

* Re: Generic Containers in Ada2005
  2011-02-10  2:03 ` Randy Brukardt
@ 2011-02-11  7:08   ` Stephen Leake
  0 siblings, 0 replies; 12+ messages in thread
From: Stephen Leake @ 2011-02-11  7:08 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

> "Bryan" <brobinson.eng@gmail.com> wrote in message 
> news:d066a30c-b356-4b28-b713-764c2b895022@d17g2000vbn.googlegroups.com...
> ...
>> I was looking for a simple queue data structure, but I noticed there
>> is not a standard Queue container.
>
> This is added by Ada 2012. See the latest draft of the Ada 2012 standard for 
> details:
> http://www.ada-auth.org/standards/12rm/html/RM-A-18-27.html
> (and the next 5 clauses as well).

There needs to be a Reset function for Peak_Use; it's not helpful to
know that sometime in the past 5 years the queue held 500 objects!

-- 
-- Stephe



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

end of thread, other threads:[~2011-02-11  7:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-09  0:43 Generic Containers in Ada2005 Bryan
2011-02-09  0:57 ` Jeffrey Carter
2011-02-09  1:26   ` Anh Vo
2011-02-09 10:56     ` Simon Wright
2011-02-09  8:33 ` Dmitry A. Kazakov
2011-02-09 16:01   ` Bryan
2011-02-09 19:10     ` Jeffrey Carter
2011-02-09 20:06     ` Simon Wright
2011-02-09 20:56   ` Maciej Sobczak
2011-02-09 21:22     ` Dmitry A. Kazakov
2011-02-10  2:03 ` Randy Brukardt
2011-02-11  7:08   ` Stephen Leake

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