pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calculations while sorting?


From: John Darrington
Subject: Re: Calculations while sorting?
Date: Tue, 5 Aug 2008 13:09:08 +0800
User-agent: Mutt/1.5.18 (2008-05-17)

On Mon, Jul 28, 2008 at 09:14:39PM -0700, Ben Pfaff wrote:
     > 1. Ben's suggestion is good idea, but I'd like to generalize upon it.
     >
     >   In my local dir, I have a number of new modules in src/math with a
     > similar interface to moments.c   How about we abstract this interface
     > into a virtual base class (let's call it "struct statistics" for
     > now).  Then instead of a "moments_reader" we can have  a polymorphic
     > "statistics_reader" is possible, which takes an array of heterogenous
     > "struct statistics" object.
     
     This is perfectly feasible.
     
     However, now I remember why I didn't do something like this
     earlier: because there is an easier way!  And this way, you don't
     need a whole menagerie of processing classes, or even just one.
     
     Instead of using sort_execute(), write a loop:
     
         sorter = sort_create_writer (ordering, casereader_get_value_cnt 
(input));
         moments = moments_create (...);
         foo = foo_create (...);
         bar = bar_create (...);
         while (casereader_read (input, &c)) 
           {
             moments_pass_one (moments, ..., ...);
             foo_process (foo, &c);
             bar_process (bar, &c);
             casewriter_write (sorter, &c);
           }
         output = casewriter_make_reader (sorter);


I suppose this is one way of doing it, but it exposes (what I have in
the past considered to be) casereader internals, and I'm not convinced
that it's easier (from the point of view of the person writing
procedures).  My idea would have done the above with something
similar to: 

 const int n_stats = 3;
 struct statistics stats[n_stats];
 stats[0] = foo_create ();
 stats[1] = bar_create ();
 stats[2] = moments_create ();
 output  = sort_execute (statistics_reader_create (input, stats, n_stats));

It just needs a very general purpose casereader/translator which is
created with the function

 struct casereader *
 statistics_reader_create (struct casereader *, struct statistics *, int);


J' 
    

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.


Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]