Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mit-eddie!uw-beaver!tektronix!nosun!dawson.fpssun.fps.com!dawson
From: dawson@fpssun.fps.com (Bryan Dawson ext 1184)
Newsgroups: comp.lang.c
Subject: Re: Sets in C (?) :idea from PASCAL
Summary: SMALL sets implemented with macros in H&S
Message-ID: <299@dawson.fpssun.fps.com>
Date: 15 Aug 88 14:25:50 GMT
References: <8808121452.AA14152@ucbvax.berkeley.edu>
Organization: Floating Point Systems
Lines: 25

In article <8808121452.AA14152@ucbvax.berkeley.edu>, U23405@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. =
============================================================================