⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set.h

📁 Vxworks下的C例子程序
💻 H
字号:
/* 
 * set.h  from the Set of Integers example, 
 * Ch. 7, C: A Reference Manual 5/e
 * Samuel P. Harbison III and Guy L. Steele Jr.
 *
 * A set package, suitable for sets of small integers in the range 0 to N-1, 
 * where N is the number of bits in an unsigned int type. 
 * Each integer is represented by a bit position; bit i is 1 if and only if 
 * i is in the set. The low-order bit is bit 0. 
 */
#include <limits.h>   /* defines CHAR_BIT */

/* Type SET is used to represent sets. */
typedef unsigned int SET;

/* SET_BITS: Maximum bits per set. */
#define SET_BITS             (sizeof(SET)*CHAR_BIT)

/* check(i): True if i can be a set element. */
#define check(i)		           (((unsigned) (i)) < SET_BITS)

/* emptyset: A set with no elements. */
#define emptyset             ((SET) 0)

/* add(s,i): Add a single integer to a set. */
#define add(set,i)		         ((set) | singleset (i))

/* singleset(i): Return a set with one element in it. */
#define singleset(i)         (((SET) 1) << (i))

/* intersect: Return intersection of two sets. */
#define intersect(set1,set2) ((set1) & (set2))

/* union: Return the union of two sets. */
#define union(set1,set2)     ((set1) | (set2))

/* setdiff: Return a set of those elements in set1 or set2,
   but not both. */
#define setdiff(set1,set2)   ((set1) ^ (set2))

/* element: True if i is in set. */
#define element(i,set)       (singleset((i)) & (set))

/* forallelements:  Perform the following statement once for
   every element of the set s, with the variable j set to
   that element. To print all the elements in s, just write
   int j;
   forallelements(j, s)
      printf("%d ", j);
*/ 
#define forallelements(j,s) \
	for ((j)=0; (j)<SET_BITS; ++(j)) if (element((j),(s)))

/* first_set_of_n_elements(n): Produce a set of size n whose
   elements are the integers from 0 through n

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -