1 /* classes: h_files */ 2 3 #ifndef RXBITSETH 4 #define RXBITSETH 5 6 /* Copyright (C) 1995, 1996 Tom Lord 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU Library General Public License as published by 10 * the Free Software Foundation; either version 2, or (at your option) 11 * any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this software; see the file COPYING. If not, write to 20 * the Free Software Foundation, 59 Temple Place - Suite 330, 21 * Boston, MA 02111-1307, USA. 22 */ 23 24 25 26 27 typedef unsigned long RX_subset; 28 #define RX_subset_bits (8 * sizeof (RX_subset)) 29 #define RX_subset_mask (RX_subset_bits - 1) 30 typedef RX_subset * rx_Bitset; 31 32 #ifdef __STDC__ 33 typedef void (*rx_bitset_iterator) (rx_Bitset, int member_index); 34 #else 35 typedef void (*rx_bitset_iterator) (); 36 #endif 37 38 /* Return the index of the word containing the Nth bit. 39 */ 40 #define rx_bitset_subset(N) ((N) / RX_subset_bits) 41 42 /* Return the conveniently-sized supset containing the Nth bit. 43 */ 44 #define rx_bitset_subset_val(B,N) ((B)[rx_bitset_subset(N)]) 45 46 47 /* Genericly combine the word containing the Nth bit with a 1 bit mask 48 * of the Nth bit position within that word. 49 */ 50 #define RX_bitset_access(B,N,OP) \ 51 ((B)[rx_bitset_subset(N)] OP rx_subset_singletons[(N) & RX_subset_mask]) 52 53 #define RX_bitset_member(B,N) RX_bitset_access(B, N, &) 54 #define RX_bitset_enjoin(B,N) RX_bitset_access(B, N, |=) 55 #define RX_bitset_remove(B,N) RX_bitset_access(B, N, &= ~) 56 #define RX_bitset_toggle(B,N) RX_bitset_access(B, N, ^= ) 57 58 /* How many words are needed for N bits? 59 */ 60 #define rx_bitset_numb_subsets(N) (((N) + RX_subset_bits - 1) / RX_subset_bits) 61 62 /* How much memory should be allocated for a bitset with N bits? 63 */ 64 #define rx_sizeof_bitset(N) (rx_bitset_numb_subsets(N) * sizeof(RX_subset)) 65 66 67 extern RX_subset rx_subset_singletons[]; 68 69 70 71 #ifdef __STDC__ 72 extern int rx_bitset_is_equal (int size, rx_Bitset a, rx_Bitset b); 73 extern int rx_bitset_is_subset (int size, rx_Bitset a, rx_Bitset b); 74 extern int rx_bitset_empty (int size, rx_Bitset set); 75 extern void rx_bitset_null (int size, rx_Bitset b); 76 extern void rx_bitset_universe (int size, rx_Bitset b); 77 extern void rx_bitset_complement (int size, rx_Bitset b); 78 extern void rx_bitset_assign (int size, rx_Bitset a, rx_Bitset b); 79 extern void rx_bitset_union (int size, rx_Bitset a, rx_Bitset b); 80 extern void rx_bitset_intersection (int size, 81 rx_Bitset a, rx_Bitset b); 82 extern void rx_bitset_difference (int size, rx_Bitset a, rx_Bitset b); 83 extern void rx_bitset_revdifference (int size, 84 rx_Bitset a, rx_Bitset b); 85 extern void rx_bitset_xor (int size, rx_Bitset a, rx_Bitset b); 86 extern unsigned long rx_bitset_hash (int size, rx_Bitset b); 87 extern int rx_bitset_population (int size, rx_Bitset a); 88 89 #else /* STDC */ 90 extern int rx_bitset_is_equal (); 91 extern int rx_bitset_is_subset (); 92 extern int rx_bitset_empty (); 93 extern void rx_bitset_null (); 94 extern void rx_bitset_universe (); 95 extern void rx_bitset_complement (); 96 extern void rx_bitset_assign (); 97 extern void rx_bitset_union (); 98 extern void rx_bitset_intersection (); 99 extern void rx_bitset_difference (); 100 extern void rx_bitset_revdifference (); 101 extern void rx_bitset_xor (); 102 extern unsigned long rx_bitset_hash (); 103 extern int rx_bitset_population (); 104 105 #endif /* STDC */ 106 107 108 109 #endif /* RXBITSETH */ 110