[Top][All Lists]

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


From: John Darrington
Subject: Re: RANK
Date: Thu, 26 May 2005 17:29:58 +0800
User-agent: Mutt/1.3.28i

On Tue, May 17, 2005 at 11:57:17PM -0700, Ben Pfaff wrote:

     I think this may be essentially what we need to solve the
     problem.  It's on my list of things to do, but I don't know when
     I'll get around to it.  If you decide to work on it, can you try
     to post a proposed design to the list before implementing?  I'm
     trying to keep the casefile design clean, so I'd like an
     opportunity to give feedback before any major changes to it are
     checked in.

After some thought and some experiment, here's my design:

1.  Add a new element to struct ccase : int case_number; and add the
    necessary code to case_copy and case_clone to preserve this value
    accross copies/clones.

2.  As the last action of every transformation (probably in 
    execute_transformations) we assign c.case_number an index starting from 0, 
    overwriting any previous value.

3.  Implement a new function in casefile.c casefile_get_case_by_index:
        struct ccase *
        casereader_get_case_by_index(struct casereader *r, int i);

    which returns a pointer to the I'th case in a casefile.

4.  A simple RANK can then be implemented thus:

    struct casefile *src = storage_source_get_casefile (vfm_source);
    struct casefile *sorted = sort_active_file_to_casefile(sort_criteria);
    struct ccase c;
    int x = 0;
    struct casereader *r;
    struct casereader *rs = casefile_get_reader(src);
     for(r = casefile_get_reader (sorted);
        casereader_read (r, &c) ;
        case_destroy (&c)) 
        struct ccase *oc = casereader_get_case_by_index(rs, c.case_number);
        case_data_rw(&c,rank_var_index)->f) = x++;

Item 3 tends to destroy the casefile abstraction somewhat.  But it's ok so long 
as nobody misuses the return value of the new function.  If that's not 
acceptable, then an alternative would be to have a function 
void casereader_set_case_by_index(struct casereader *, int index, union value 

... although here the casereader has become a casewriter (perhaps 
case_iterator would be a better term anyway)


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

Attachment: pgppEdYKkexqT.pgp
Description: PGP signature

reply via email to

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