• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __GATE_SET_H
2 #define __GATE_SET_H
3 
4 /*	set.h
5 
6 	The following is a general-purpose set library originally developed
7 	by Hank Dietz and enhanced by Terence Parr to allow dynamic sets.
8 
9 	Sets are now structs containing the #words in the set and
10 	a pointer to the actual set words.
11 
12 	1987 by Hank Dietz
13 
14 	Modified by:
15 		Terence Parr
16 		Purdue University
17 		October 1989
18 
19 		Added ANSI prototyping Dec. 1992 -- TJP
20 */
21 
22 #include "pcctscfg.h"
23 
24 #ifdef NOT_USED /* SEE config.h */
25 /* Define usable bits per unsigned int word */
26 #ifdef PC
27 #define WORDSIZE 16
28 #define LogWordSize	4
29 #else
30 #define	WORDSIZE 32
31 #define LogWordSize 5
32 #endif
33 #define BytesPerWord	sizeof(unsigned)
34 #endif
35 
36 #define	SETSIZE(a) ((a).n<<LogWordSize)		/* Maximum items per set */
37 #define	MODWORD(x) ((x) & (WORDSIZE-1))		/* x % WORDSIZE */
38 #define	DIVWORD(x) ((x) >> LogWordSize)		/* x / WORDSIZE */
39 #define	nil	(~((unsigned) 0))	/* An impossible set member all bits on (big!) */
40 
41 typedef struct _set {
42 			unsigned int n;		/* Number of words in set */
43 			unsigned *setword;
44 		} set;
45 
46 #define set_init	{0, NULL}
47 #define set_null(a)	((a).setword==NULL)
48 
49 #define	NumBytes(x)		(((x)>>3)+1)						/* Num bytes to hold x */
50 #define	NumWords(x)		((((unsigned)(x))>>LogWordSize)+1)	/* Num words to hold x */
51 
52 
53 /* M a c r o s */
54 
55 /* make arg1 a set big enough to hold max elem # of arg2 */
56 #define set_new(a,_max) \
57 if (((a).setword=(unsigned *)calloc(NumWords(_max),BytesPerWord))==NULL) \
58         fprintf(stderr, "set_new: Cannot allocate set with max of %d\n", _max); \
59         (a).n = NumWords(_max);
60 
61 #define set_free(a)									\
62 	{if ( (a).setword != NULL ) free((char *)((a).setword));	\
63 	(a) = empty;}
64 
65 #ifdef __USE_PROTOS
66 extern void set_size( unsigned );
67 extern unsigned int set_deg( set );
68 extern set set_or( set, set );
69 extern set set_and( set, set );
70 extern set set_dif( set, set );
71 extern set set_of( unsigned );
72 extern void set_ext( set *, unsigned int );
73 extern set set_not( set );
74 extern int set_equ( set, set );
75 extern int set_sub( set, set );
76 extern unsigned set_int( set );
77 extern int set_el( unsigned, set );
78 extern int set_nil( set );
79 extern char * set_str( set );
80 extern set set_val( register char * );
81 extern void set_orel( unsigned, set * );
82 extern void set_orin( set *, set );
83 extern void set_andin( set *, set );
84 extern void set_rm( unsigned, set );
85 extern void set_clr( set );
86 extern set set_dup( set );
87 extern void set_PDQ( set, register unsigned * );
88 extern unsigned *set_pdq( set );
89 extern void _set_pdq( set a, register unsigned *q );
90 extern unsigned int set_hash( set, register unsigned int );
91 #else
92 extern void set_size();
93 extern unsigned int set_deg();
94 extern set set_or();
95 extern set set_and();
96 extern set set_dif();
97 extern set set_of();
98 extern void set_ext();
99 extern set set_not();
100 extern int set_equ();
101 extern int set_sub();
102 extern unsigned set_int();
103 extern int set_el();
104 extern int set_nil();
105 extern char * set_str();
106 extern set set_val();
107 extern void set_orel();
108 extern void set_orin();
109 extern void set_andin();
110 extern void set_rm();
111 extern void set_clr();
112 extern set set_dup();
113 extern void set_PDQ();
114 extern unsigned *set_pdq();
115 extern void _set_pdq();
116 extern unsigned int set_hash();
117 #endif
118 
119 extern set empty;
120 
121 #endif
122