pspp-dev
[Top][All Lists]
Advanced

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

Re: Reuse of structs


From: Ben Pfaff
Subject: Re: Reuse of structs
Date: Mon, 26 Jan 2015 08:29:54 -0800
User-agent: Mutt/1.5.23 (2014-03-12)

On Sat, Jan 24, 2015 at 07:30:14AM +0100, John Darrington wrote:
> There are a number of definitions of what seem to be very similar
> structs, which are used for similar purpose, viz:
> 
> In crosstabs.q:
> 
> /* A single table entry for general mode. */
> struct table_entry
>   {
>     struct hmap_node node;      /* Entry in hash table. */
>     double freq;                /* Frequency count. */
>     union value values[1];    /* Values. */
>   };
> 
> In freq.h:
> 
> /* Frequency table entry. */
> struct freq
>   {
>     struct hmap_node hmap_node; /* Element in hash table. */
>     union value value;          /* The value. */
>     double count;             /* The number of occurrences of the value. */
>   };
> 
> and in piechart.h:
> 
> struct slice
>   {
>     struct string label;
>     double magnitude;
>   };
> 
> 
> I don't know what extent we can re-use the code which accesses these
> structs, but I think it would be beneficial to keep that option open
> and combine these definitions into one common definition.

The crosstabs table entry and frequency table entry are quite a bit
different in practice because crosstabs entries have an arbitrary number
of values, whereas frequency table entry always have exactly one.  I
guess that one could regard the frequency table entry as a special case
of a crosstabs entry (that has one value), though.  If that's valuable
for reducing the amount of code, then I'm in favor of it, but if it just
means that we have to change a lot of code to use a single struct, it's
not obviously worthwhile.

>From the struct definition, at least, it's not obvious that a slice is
the same thing, since it doesn't appear to be part of a table.



reply via email to

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