From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Dynamic array allocation and STL equivalents?
Date: Fri, 11 Feb 2005 15:41:39 +0100
Date: 2005-02-11T15:41:39+01:00 [thread overview]
Message-ID: <13r5d1sfsg55d$.1u0p9rdnt3zcy.dlg@40tude.net> (raw)
In-Reply-To: 1108127216.221977.60830@o13g2000cwo.googlegroups.com
On 11 Feb 2005 05:06:56 -0800, brian.b.mcguinness@lmco.com wrote:
[...]
Dynamic allocation of arrays is no problem in Ada.
> One interesting project would be to create an object class hierarchy to
> implement APL arrays. In APL, the lengths of an array's dimensions can
> change, e.g. by concatenating new rows or columns onto a matrix, or
> concatenating two matrices, and the number of dimensions can also
> change, e.g. by "laminating" two 12x30 arrays to form a 2x12x30 array.
> In C++, an obvious solution would be to use STL vectors, e.g.:
>
> class RealArray {
> private:
> vector <unsigned long> dimensions;
> vector <double> data;
> public:
> // define an indexing operator[] to use the dimensions
> // vector to translate sets of indices into offsets
> // into the data array
Index of a multi-dimensional array is a tuple. That won't work in C++ (you
cannot override "," to support: A[i,j,k]). Neither works it in Ada.
Though in Ada you could have a type:
type Index is array (Integer range <>) of Integer; -- Tuple
then in Real_Array:
type Real_Array is private;
function Get (Container : Real_Array; Element : Index) return Float;
private
type Index_Ptr is access Index;
type Real_Array is new Ada.Finalization.Controlled with record
Lower_Bound : Index_Ptr;
Upper_Bound : Index_Ptr;
Data : <whatsoever>
...
procedure Finalize (X : in out Real_Array);
-- Destructor is a handy thing
Then you could index your arrays like:
Get (My_Array, (I, J, K));
Further, if you wished to support slices sub-matrices etc, that would
require a lot of work. Alas, in Ada you cannot override either "()" or ".."
or "in" (membership test) or aggregates. So the interface would be rather
clumsy.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2005-02-11 14:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-11 13:06 Dynamic array allocation and STL equivalents? brian.b.mcguinness
2005-02-11 13:43 ` Jeff C
2005-02-14 15:23 ` Marc A. Criley
2005-02-11 14:41 ` Dmitry A. Kazakov [this message]
2005-02-11 15:50 ` Adrien Plisson
2005-02-11 17:47 ` REH
2005-02-12 9:28 ` Dmitry A. Kazakov
2005-02-12 18:52 ` Robert A Duff
2005-02-11 17:24 ` Bobby D. Bryant
2005-02-12 0:06 ` Robert A Duff
2005-02-12 3:45 ` Bobby D. Bryant
2005-02-11 18:07 ` Matthew Heaney
2005-02-11 18:36 ` Martin Krischik
2005-02-11 19:35 ` brian.b.mcguinness
2005-02-12 1:04 ` Jeffrey Carter
2005-02-12 6:19 ` Bobby D. Bryant
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox