Path: utzoo!attcan!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: Sets in C (?) :idea from PASCAL Message-ID: <594@philmds.UUCP> Date: 17 Aug 88 09:12:20 GMT References: <8808121452.AA14152@ucbvax.berkeley.edu> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 30 Summary: In article <8808121452.AA14152@ucbvax.berkeley.edu> U23405@UICVM.BITNET writes: >(Please don't flame at me, I'm just being curious.) :-) > >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) An obvious way to implement this in C could be using an (array of) integer(s) and the logical operations &, |, ~, and ^ to perform operations on these values. The bits of the integer(s) should each correspond to a data element of a certain type (the type in: set of type). So the GAME of this implementation is such that each bit of the SET MATCHes a value of the base type (been watching tennis a bit too much lately 8-). Of course this rules out type checking - unless you do something like putting the integer(s) into a struct and adding a type identifier to this struct. The nice thing about using the logical operators on integers is that this opens the possibility to code the stuff using macro's, thus improving speed. The use of bit arrays forbids any large base type (for example: set of integer). Dunno how that's handled in Pascal, but I seem to remember that the language does not pose any restrictions on the base type but implementations do. In this case one will have to resort to linked lists or something alike. Sounds interesting ... might even give it a try myself 8-). Leo.