home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / Set 32 / set32.c next >
Encoding:
C/C++ Source or Header  |  1997-07-21  |  6.0 KB  |  334 lines  |  [TEXT/R*ch]

  1. /**********************************************************
  2.  
  3.     Copyright (c) Dale Semchishen 1997
  4.     All Rights Reserved
  5.  
  6.     set32.c
  7.  
  8.     Description:
  9.         32 bit set manipulation library for all platforms
  10.  
  11.         This library consists of macros and functions that
  12.         provide set manipulation services.
  13.  
  14.     Public macros and functions:
  15.         set32_Assign()        - define all bits in a set
  16.         set32_Not()            - invert all bits in a set
  17.         set32_And()            - AND two sets together
  18.         set32_Or()            - OR two sets together
  19.         set32_Xor()            - Exclusive-OR two sets together
  20.         set32_Tst()            - test if any bits are set
  21.         set32_Count()        - count how many bits are set
  22.  
  23.         set32_Set1()        - set one bit
  24.         set32_Clr1()        - clear one bit
  25.         set32_Not1()        - invert one bit
  26.         set32_Tst1()        - test if a bit is set
  27.  
  28.  **********************************************************/
  29.  
  30. #include <set32.h>
  31.  
  32.  
  33. /*----------------- Forward References -------------------*/
  34.  
  35. extern BYTE gSET32_bitcount[];
  36.  
  37.  
  38.  
  39. /**********************************************************
  40.  
  41.     set32_Count - count how many bits are set
  42.  
  43.     Description:
  44.  
  45.     Return value:
  46.         0 to 32
  47.  
  48. **********************************************************/
  49. BYTE set32_Count
  50. (
  51.     sSET32    bitset        /* I: the bitset to count the '1's of */
  52. )
  53. {
  54.     union
  55.     {
  56.         sSET32    normal;
  57.         BYTE    fourbytes[4];
  58.  
  59.     } work;
  60.  
  61.     register BYTE *byte_ptr = work.fourbytes;
  62.     register BYTE *array_ptr = gSET32_bitcount;
  63.  
  64.     work.normal = bitset;
  65.  
  66.     return( array_ptr[ *byte_ptr++ ] +
  67.             array_ptr[ *byte_ptr++ ] +
  68.             array_ptr[ *byte_ptr++ ] +
  69.             array_ptr[ *byte_ptr ] );
  70. }
  71.  
  72.  
  73.  
  74.  
  75. static BYTE gSET32_bitcount[256] =
  76. {
  77.     0,  /*   0 */
  78.     1,  /*   1 */
  79.     1,  /*   2 */
  80.     2,  /*   3 */
  81.     1,  /*   4 */
  82.     2,  /*   5 */
  83.     2,  /*   6 */
  84.     3,  /*   7 */
  85.     1,  /*   8 */
  86.     2,  /*   9 */
  87.     2,  /*  10 */
  88.     3,  /*  11 */
  89.     2,  /*  12 */
  90.     3,  /*  13 */
  91.     3,  /*  14 */
  92.     4,  /*  15 */
  93.     1,  /*  16 */
  94.     2,  /*  17 */
  95.     2,  /*  18 */
  96.     3,  /*  19 */
  97.     2,  /*  20 */
  98.     3,  /*  21 */
  99.     3,  /*  22 */
  100.     4,  /*  23 */
  101.     2,  /*  24 */
  102.     3,  /*  25 */
  103.     3,  /*  26 */
  104.     4,  /*  27 */
  105.     3,  /*  28 */
  106.     4,  /*  29 */
  107.     4,  /*  30 */
  108.     5,  /*  31 */
  109.     1,  /*  32 */
  110.     2,  /*  33 */
  111.     2,  /*  34 */
  112.     3,  /*  35 */
  113.     2,  /*  36 */
  114.     3,  /*  37 */
  115.     3,  /*  38 */
  116.     4,  /*  39 */
  117.     2,  /*  40 */
  118.     3,  /*  41 */
  119.     3,  /*  42 */
  120.     4,  /*  43 */
  121.     3,  /*  44 */
  122.     4,  /*  45 */
  123.     4,  /*  46 */
  124.     5,  /*  47 */
  125.     2,  /*  48 */
  126.     3,  /*  49 */
  127.     3,  /*  50 */
  128.     4,  /*  51 */
  129.     3,  /*  52 */
  130.     4,  /*  53 */
  131.     4,  /*  54 */
  132.     5,  /*  55 */
  133.     3,  /*  56 */
  134.     4,  /*  57 */
  135.     4,  /*  58 */
  136.     5,  /*  59 */
  137.     4,  /*  60 */
  138.     5,  /*  61 */
  139.     5,  /*  62 */
  140.     6,  /*  63 */
  141.     1,  /*  64 */
  142.     2,  /*  65 */
  143.     2,  /*  66 */
  144.     3,  /*  67 */
  145.     2,  /*  68 */
  146.     3,  /*  69 */
  147.     3,  /*  70 */
  148.     4,  /*  71 */
  149.     2,  /*  72 */
  150.     3,  /*  73 */
  151.     3,  /*  74 */
  152.     4,  /*  75 */
  153.     3,  /*  76 */
  154.     4,  /*  77 */
  155.     4,  /*  78 */
  156.     5,  /*  79 */
  157.     2,  /*  80 */
  158.     3,  /*  81 */
  159.     3,  /*  82 */
  160.     4,  /*  83 */
  161.     3,  /*  84 */
  162.     4,  /*  85 */
  163.     4,  /*  86 */
  164.     5,  /*  87 */
  165.     3,  /*  88 */
  166.     4,  /*  89 */
  167.     4,  /*  90 */
  168.     5,  /*  91 */
  169.     4,  /*  92 */
  170.     5,  /*  93 */
  171.     5,  /*  94 */
  172.     6,  /*  95 */
  173.     2,  /*  96 */
  174.     3,  /*  97 */
  175.     3,  /*  98 */
  176.     4,  /*  99 */
  177.     3,  /* 100 */
  178.     4,  /* 101 */
  179.     4,  /* 102 */
  180.     5,  /* 103 */
  181.     3,  /* 104 */
  182.     4,  /* 105 */
  183.     4,  /* 106 */
  184.     5,  /* 107 */
  185.     4,  /* 108 */
  186.     5,  /* 109 */
  187.     5,  /* 110 */
  188.     6,  /* 111 */
  189.     3,  /* 112 */
  190.     4,  /* 113 */
  191.     4,  /* 114 */
  192.     5,  /* 115 */
  193.     4,  /* 116 */
  194.     5,  /* 117 */
  195.     5,  /* 118 */
  196.     6,  /* 119 */
  197.     4,  /* 120 */
  198.     5,  /* 121 */
  199.     5,  /* 122 */
  200.     6,  /* 123 */
  201.     5,  /* 124 */
  202.     6,  /* 125 */
  203.     6,  /* 126 */
  204.     7,  /* 127 */
  205.     1,  /* 128 */
  206.     2,  /* 129 */
  207.     2,  /* 130 */
  208.     3,  /* 131 */
  209.     2,  /* 132 */
  210.     3,  /* 133 */
  211.     3,  /* 134 */
  212.     4,  /* 135 */
  213.     2,  /* 136 */
  214.     3,  /* 137 */
  215.     3,  /* 138 */
  216.     4,  /* 139 */
  217.     3,  /* 140 */
  218.     4,  /* 141 */
  219.     4,  /* 142 */
  220.     5,  /* 143 */
  221.     2,  /* 144 */
  222.     3,  /* 145 */
  223.     3,  /* 146 */
  224.     4,  /* 147 */
  225.     3,  /* 148 */
  226.     4,  /* 149 */
  227.     4,  /* 150 */
  228.     5,  /* 151 */
  229.     3,  /* 152 */
  230.     4,  /* 153 */
  231.     4,  /* 154 */
  232.     5,  /* 155 */
  233.     4,  /* 156 */
  234.     5,  /* 157 */
  235.     5,  /* 158 */
  236.     6,  /* 159 */
  237.     2,  /* 160 */
  238.     3,  /* 161 */
  239.     3,  /* 162 */
  240.     4,  /* 163 */
  241.     3,  /* 164 */
  242.     4,  /* 165 */
  243.     4,  /* 166 */
  244.     5,  /* 167 */
  245.     3,  /* 168 */
  246.     4,  /* 169 */
  247.     4,  /* 170 */
  248.     5,  /* 171 */
  249.     4,  /* 172 */
  250.     5,  /* 173 */
  251.     5,  /* 174 */
  252.     6,  /* 175 */
  253.     3,  /* 176 */
  254.     4,  /* 177 */
  255.     4,  /* 178 */
  256.     5,  /* 179 */
  257.     4,  /* 180 */
  258.     5,  /* 181 */
  259.     5,  /* 182 */
  260.     6,  /* 183 */
  261.     4,  /* 184 */
  262.     5,  /* 185 */
  263.     5,  /* 186 */
  264.     6,  /* 187 */
  265.     5,  /* 188 */
  266.     6,  /* 189 */
  267.     6,  /* 190 */
  268.     7,  /* 191 */
  269.     2,  /* 192 */
  270.     3,  /* 193 */
  271.     3,  /* 194 */
  272.     4,  /* 195 */
  273.     3,  /* 196 */
  274.     4,  /* 197 */
  275.     4,  /* 198 */
  276.     5,  /* 199 */
  277.     3,  /* 200 */
  278.     4,  /* 201 */
  279.     4,  /* 202 */
  280.     5,  /* 203 */
  281.     4,  /* 204 */
  282.     5,  /* 205 */
  283.     5,  /* 206 */
  284.     6,  /* 207 */
  285.     3,  /* 208 */
  286.     4,  /* 209 */
  287.     4,  /* 210 */
  288.     5,  /* 211 */
  289.     4,  /* 212 */
  290.     5,  /* 213 */
  291.     5,  /* 214 */
  292.     6,  /* 215 */
  293.     4,  /* 216 */
  294.     5,  /* 217 */
  295.     5,  /* 218 */
  296.     6,  /* 219 */
  297.     5,  /* 220 */
  298.     6,  /* 221 */
  299.     6,  /* 222 */
  300.     7,  /* 223 */
  301.     3,  /* 224 */
  302.     4,  /* 225 */
  303.     4,  /* 226 */
  304.     5,  /* 227 */
  305.     4,  /* 228 */
  306.     5,  /* 229 */
  307.     5,  /* 230 */
  308.     6,  /* 231 */
  309.     4,  /* 232 */
  310.     5,  /* 233 */
  311.     5,  /* 234 */
  312.     6,  /* 235 */
  313.     5,  /* 236 */
  314.     6,  /* 237 */
  315.     6,  /* 238 */
  316.     7,  /* 239 */
  317.     4,  /* 240 */
  318.     5,  /* 241 */
  319.     5,  /* 242 */
  320.     6,  /* 243 */
  321.     5,  /* 244 */
  322.     6,  /* 245 */
  323.     6,  /* 246 */
  324.     7,  /* 247 */
  325.     5,  /* 248 */
  326.     6,  /* 249 */
  327.     6,  /* 250 */
  328.     7,  /* 251 */
  329.     6,  /* 252 */
  330.     7,  /* 253 */
  331.     7,  /* 254 */
  332.     8   /* 255 */
  333. };
  334.