home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnurx.zip / rx / rxbitset.h < prev    next >
C/C++ Source or Header  |  1995-12-31  |  4KB  |  116 lines

  1. /* classes: h_files */
  2.  
  3. #ifndef RXBITSETH
  4. #define RXBITSETH
  5.  
  6. /***********************************************************
  7.  
  8. Copyright 1995 by Tom Lord
  9.  
  10.                         All Rights Reserved
  11.  
  12. Permission to use, copy, modify, and distribute this software and its 
  13. documentation for any purpose and without fee is hereby granted, 
  14. provided that the above copyright notice appear in all copies and that
  15. both that copyright notice and this permission notice appear in 
  16. supporting documentation, and that the name of the copyright holder not be
  17. used in advertising or publicity pertaining to distribution of the
  18. software without specific, written prior permission.  
  19.  
  20. Tom Lord DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  21. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  22. EVENT SHALL TOM LORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  23. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  24. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  25. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  26. PERFORMANCE OF THIS SOFTWARE.
  27.  
  28. ******************************************************************/
  29.  
  30.  
  31.  
  32.  
  33. typedef unsigned long RX_subset;
  34. #define RX_subset_bits    (8 * sizeof (RX_subset))
  35. #define RX_subset_mask    (RX_subset_bits - 1)
  36. typedef RX_subset * rx_Bitset;
  37.  
  38. #ifdef __STDC__
  39. typedef void (*rx_bitset_iterator) (rx_Bitset, int member_index);
  40. #else
  41. typedef void (*rx_bitset_iterator) ();
  42. #endif
  43.  
  44. /* Return the index of the word containing the Nth bit.
  45.  */
  46. #define rx_bitset_subset(N)  ((N) / RX_subset_bits)
  47.  
  48. /* Return the conveniently-sized supset containing the Nth bit.
  49.  */
  50. #define rx_bitset_subset_val(B,N)  ((B)[rx_bitset_subset(N)])
  51.  
  52.  
  53. /* Genericly combine the word containing the Nth bit with a 1 bit mask
  54.  * of the Nth bit position within that word.
  55.  */
  56. #define RX_bitset_access(B,N,OP) \
  57.   ((B)[rx_bitset_subset(N)] OP rx_subset_singletons[(N) & RX_subset_mask])
  58.  
  59. #define RX_bitset_member(B,N)   RX_bitset_access(B, N, &)
  60. #define RX_bitset_enjoin(B,N)   RX_bitset_access(B, N, |=)
  61. #define RX_bitset_remove(B,N)   RX_bitset_access(B, N, &= ~)
  62. #define RX_bitset_toggle(B,N)   RX_bitset_access(B, N, ^= )
  63.  
  64. /* How many words are needed for N bits?
  65.  */
  66. #define rx_bitset_numb_subsets(N) (((N) + RX_subset_bits - 1) / RX_subset_bits)
  67.  
  68. /* How much memory should be allocated for a bitset with N bits?
  69.  */
  70. #define rx_sizeof_bitset(N)    (rx_bitset_numb_subsets(N) * sizeof(RX_subset))
  71.  
  72.  
  73. extern RX_subset rx_subset_singletons[];
  74.  
  75.  
  76.  
  77. #ifdef __STDC__
  78. extern int rx_bitset_is_equal (int size, rx_Bitset a, rx_Bitset b);
  79. extern int rx_bitset_is_subset (int size, rx_Bitset a, rx_Bitset b);
  80. extern int rx_bitset_empty (int size, rx_Bitset set);
  81. extern void rx_bitset_null (int size, rx_Bitset b);
  82. extern void rx_bitset_universe (int size, rx_Bitset b);
  83. extern void rx_bitset_complement (int size, rx_Bitset b);
  84. extern void rx_bitset_assign (int size, rx_Bitset a, rx_Bitset b);
  85. extern void rx_bitset_union (int size, rx_Bitset a, rx_Bitset b);
  86. extern void rx_bitset_intersection (int size,
  87.                     rx_Bitset a, rx_Bitset b);
  88. extern void rx_bitset_difference (int size, rx_Bitset a, rx_Bitset b);
  89. extern void rx_bitset_revdifference (int size,
  90.                      rx_Bitset a, rx_Bitset b);
  91. extern void rx_bitset_xor (int size, rx_Bitset a, rx_Bitset b);
  92. extern unsigned long rx_bitset_hash (int size, rx_Bitset b);
  93. extern int rx_bitset_population (int size, rx_Bitset a);
  94.  
  95. #else /* STDC */
  96. extern int rx_bitset_is_equal ();
  97. extern int rx_bitset_is_subset ();
  98. extern int rx_bitset_empty ();
  99. extern void rx_bitset_null ();
  100. extern void rx_bitset_universe ();
  101. extern void rx_bitset_complement ();
  102. extern void rx_bitset_assign ();
  103. extern void rx_bitset_union ();
  104. extern void rx_bitset_intersection ();
  105. extern void rx_bitset_difference ();
  106. extern void rx_bitset_revdifference ();
  107. extern void rx_bitset_xor ();
  108. extern unsigned long rx_bitset_hash ();
  109. extern int rx_bitset_population ();
  110.  
  111. #endif /* STDC */
  112.  
  113.  
  114.  
  115. #endif  /* RXBITSETH */
  116.