comp.lang.ada
 help / color / mirror / Atom feed
* Spark sorting algorithm with generic input data
@ 2010-09-19 11:14 chuck
  2010-09-19 17:30 ` Phil Thornley
  0 siblings, 1 reply; 2+ messages in thread
From: chuck @ 2010-09-19 11:14 UTC (permalink / raw)


hi folks,
at the moment i become acquainted with ada as well as spark language.
i implemented a bubble sort algorithm with generic input values in ada
and tried a transferring to spark. implementing and proofing the
algorithm in spark was not a problem at all, but i'm not sure how to
handle generic input values. To my knowledge the concept of generics
is not available in spark, therefore i would appreciate any valuable
comments on how to make use of data abstraction.
thx in advance.

jonas



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

* Re: Spark sorting algorithm with generic input data
  2010-09-19 11:14 Spark sorting algorithm with generic input data chuck
@ 2010-09-19 17:30 ` Phil Thornley
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Thornley @ 2010-09-19 17:30 UTC (permalink / raw)


On 19 Sep, 12:14, chuck <jonaspen...@googlemail.com> wrote:
> hi folks,
> at the moment i become acquainted with ada as well as spark language.
> i implemented a bubble sort algorithm with generic input values in ada
> and tried a transferring to spark. implementing and proofing the
> algorithm in spark was not a problem at all, but i'm not sure how to
> handle generic input values. To my knowledge the concept of generics
> is not available in spark, therefore i would appreciate any valuable
> comments on how to make use of data abstraction.

You are correct that SPARK does not support generics - there have been
some suggestions that they are actively in development but no dates
have been given.

When it comes to using a SPARK component (such as a sort operation) or
data structure (such as a list or tree) with different data types,
there are two basic approaches:
1. Write the code so that it makes the minimum possible assumptions
about the data type - then changing the data type should be as simple
as possible, but this does require a change to the code of the
component (even if the only change is the declaration of the element
type).
2. If the identity of each element of the type can be encapsulated in,
say, an integer (eg if there is a 'key' value that can be calculated
for each element) then write the SPARK code using an Integer element
and only pass the key values to the operations.  Use your own
'pool' (ie array of elements) to store the actual elements, then the
outputs of the operations tell you how to access that array.

For example, using the second approach for a sort procedure, store
values in the key array and the element array in parallel, then the
sorted key array tells you the sequence of elements in the data array.

Or, for a list or tree, every operation that stores or reads a data
element actually calls the relevant operation with the key value for
the element, and the operation has an 'out' parameter that is the
index of that key within the structure - so this tells you which
element of your actual data array to read/write.  (This method has the
restriction that no key element can move within the data structure
once stored in there.)

Cheers,

Phil



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

end of thread, other threads:[~2010-09-19 17:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-19 11:14 Spark sorting algorithm with generic input data chuck
2010-09-19 17:30 ` Phil Thornley

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