[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calculations while sorting?
From: |
Ben Pfaff |
Subject: |
Re: Calculations while sorting? |
Date: |
Mon, 28 Jul 2008 21:14:39 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
John Darrington <address@hidden> writes:
> On Sun, Jul 27, 2008 at 09:21:56PM -0700, Ben Pfaff wrote:
>
> It would be easy to create a "moments_reader" that does calculations
> like this as side effects and otherwise passes cases through
> without modification.
>
> There would be no need to make this part of sorting. Just make a
> "moments_reader" out of your data and then pass the
> moments_reader to sort_execute.
>
> Having thought about this, I have some more ideas:
>
> 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);
Note that this is all sort_execute() does, without the extra
moments and whatever else thrown in, as you can see from its
source:
struct casereader *
sort_execute (struct casereader *input, struct case_ordering *ordering)
{
struct casewriter *output =
sort_create_writer (ordering, casereader_get_value_cnt (input));
casereader_transfer (input, output);
return casewriter_make_reader (output);
}
--
Peter Seebach on managing engineers:
"It's like herding cats, only most of the engineers are already
sick of laser pointers."