Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!cbmvax!snark!eric From: eric@snark.UUCP (Eric S. Raymond) Newsgroups: comp.lang.c Subject: Re: Sets in C (?) :idea from PASCAL Summary: Enough already, here's an implementation. Message-ID: Date: 22 Aug 88 11:14:55 GMT References: <8808121452.AA14152@ucbvax.berkeley.edu> <2732@boulder.colorado.edu> <597@sbsvax.uucp> <1168@ttds.uucp> Organization: Eric Conspiracy Secret Laboratories Lines: 27 It's not like this is a difficult problem or anything. /* bitmacros.h -- bitmap-allocation and get/set macros */ #define ALLOC_BITS(n) calloc((unsigned) ALLOC_LEN(n), 1) #define REALLOC_BITS(p, m, n) if (m>n)(void)realloc(p,(unsigned)ALLOC_LEN(n)) #ifndef UNPACKED #define ALLOC_LEN(n) (((n) >> 3) + 1) #define GET_BIT(map, b) ((map)[(b) >> 3] & (1 << ((b) % 8))) #define SET_BIT(map, b) ((map)[(b) >> 3] |= (1 << ((b) % 8))) #define CLEAR_BIT(map, b) ((map)[(b) >> 3] &= ~(1 << ((b) % 8))) #else #define ALLOC_LEN(n) (n) #define GET_BIT(map, b) map[b] #define SET_BIT(map, b) (map[b] = 1) #define CLEAR_BIT(map, b) (map[b] = 0) #endif /* !UNPACKED */ /* bitmacros.h ends here */ Can we drop this subject now? Please? -- Eric S. Raymond (the mad mastermind of TMN-Netnews) UUCP: ..!{uunet,att,rutgers!vu-vlsi}!snark!eric @nets: eric@snark.UUCP Post: 22 South Warren Avenue, Malvern, PA 19355 Phone: (215)-296-5718