Sets in C (?) :idea from PASCAL

Bryan Dawson ext 1184 dawson at fpssun.fps.com
Tue Aug 16 00:25:50 AEST 1988


In article <8808121452.AA14152 at ucbvax.berkeley.edu>, U23405 at UICVM.BITNET writes:
> In PASCAL, there is a datatype called SET that (obviously) deals with sets.
> What I would like to know is whether anyone has tried to implement this
> datatype in C (either by a system header file or by typedefs). Any comments
> would be helpful. (And I mean *ANY* comments)
> 

    There is an implementation of SMALL sets (using the bits in a
presumably 32 bit unsigned int as a bit array of elements) which
is outlined in 'C A Reference Manual' by Harbison & Steele (Pg 174
and 175 in 2nd ed.).
    Basically, they #define macros which use bitwise operations to
implement intersection, union, difference, membership, etc...
I have used a refined version of this technique to implement
SPECIFIC well defined sets for applications which really needed
them.  I believe that a well behaved GENERIC set type similar to
PASCAL would take quite a bit of effort to implement well in C.
Luckily, I find that it is often possible to tailor the requirements
to meet the application and thus enable a simple implementation similar
to the one in H&S quite workable.
-- 
============================================================================
= Bryan Dawson   tektronix!fpssun!dawson      ...The story you have just   =
=  read is true, reality was subsequently changed to protect the innocent. =
============================================================================ 



More information about the Comp.lang.c mailing list