comp.lang.ada
 help / color / mirror / Atom feed
From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Re: Emulation of MatLab functions?
Date: Tue, 17 Jul 2001 12:44:43 +0200
Date: 2001-07-17T12:44:43+02:00	[thread overview]
Message-ID: <3B54171B.8AD28D4@nbi.dk> (raw)
In-Reply-To: 3B5386B1.AF0E7671@top.monad.net

Steve:

John Thornley published a sorting package somewhere.

Find should be pretty easy to implement. Something along the
lines of:

   --  The following is distributed according to the GNU GPL
or the
   --  ADCL (when it is finished).

   generic
      type Element_Type is private;
      type Element_Array is array (Integer range <>) of
Element_Type;
      with function Match (Item : Element_Type) return
Boolean;
   function Find (Source : Element_Array) return
Element_Array;

   function Find (Source : Element_Array) return
Element_Array is
      Match_Count : Natural := 0;
      Matches     : array (Source'Range) of Boolean;
   begin
      for Index in Source'Range loop
         Matches (Index) := Match (Source (Index));

         if Matches (Index) then
            Match_Count := Match_Count + 1;
         end if;
      end loop;

      declare
         Result       : Element_Array (1 .. Match_Count);
         Target_Index : Natural := 0;
      begin
         for Source_Index in Source'Range loop
            if Matches (Source_Index) then
               Target_Index := Target_Index + 1;
               Result (Target_Index) := Source
(Source_Index);
            end if;
         end loop;

         return Result;
      end;
   end Find;

Jacob
-- 
Warning: Dates in calendars are closer than they appear.



      reply	other threads:[~2001-07-17 10:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-17  0:28 Emulation of MatLab functions? Steve O'Neill
2001-07-17 10:44 ` Jacob Sparre Andersen [this message]
replies disabled

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