Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
bitset.h
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 #ifndef bitset_INCLUDED
00037 #define bitset_INCLUDED
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00042 /* ====================================================================
00043  * ====================================================================
00044  *
00045  *
00046  * Revision history:
00047  *  05-01-93 - Original Version
00048  *
00049  * Description:
00050  *
00051  *      Bitset interface.  See below for details.
00052  *
00053  * ====================================================================
00054  * ====================================================================
00055  */
00056 
00057 
00058 #ifdef _KEEP_RCS_ID
00059 #endif /* _KEEP_RCS_ID */
00060 
00061 /* This package implements sets of nonnegative INTs.  These can be
00062  * manipulated with a fairly complete repertoire of set functions.
00063  * The sets are represented with bit strings for efficiency of both
00064  * space and run time.  The vector that represents these sets is grown
00065  * as necessary to accommodate the results of the various operations.
00066  * In spite of this, the client of the package retains control over
00067  * storage allocation by providing memory allocation pools
00068  * (MEM_POOLs).  The representations are never automatically trimmed,
00069  * so that the representation of any given bit set will be large
00070  * enough to hold the largest number that it ever held.
00071  *
00072  *
00073  *
00074  * Destructive Operations Conventions
00075  * ==================================
00076  *
00077  *
00078  * This package contains a number of functions that implement
00079  * destructive operations.  The purpose of these operations is
00080  * efficiency both of the operations themselves and of memory usage.
00081  * Some of the destructive operations may still need to expand the
00082  * storage allocated to the set.  When this happens, the set may need
00083  * to be copied.  Thus you can not count on the side effects of these
00084  * operations, only on the correctness of their returned values.
00085  * Functions in this package that can have a destructive effect on a
00086  * one of their arguments always have a name that ends with the letter
00087  * D.  Only the first argument of such functions is ever destructively
00088  * modified.  All destructive operations return a pointer to the set.
00089  * In the normal case this will be the same as their first argument,
00090  * but sometimes the set will have to be copied in order to perform
00091  * the operation.  So the client should not rely on the side effects
00092  * of destructive operations.  Instead, one should use their returned
00093  * values.  For now, destructive operations only expand storage, and
00094  * never shrink it.
00095  *
00096  *
00097  * Replacement Operations Conventions
00098  * ==================================
00099  *
00100  *
00101  * This package implements a number of "replacement" operations.
00102  * These are very similar to the "destructive" versions, but also take
00103  * a pointer to the result, which is not used in the calculation.
00104  * These all end with the letter R. 
00105  *
00106  *
00107  * Storage Allocation
00108  * ==================
00109  *
00110  *
00111  * The client of this package has full control over storage allocation
00112  * for BS's.  This is achieved by passing storage allocation pools
00113  * (MEM_POOLs) to the functions that may need to use them.  All
00114  * storage allocated for a set is "flat", which is to say that from
00115  * the point of view of storage allocation, each BS may be seen as a
00116  * single array containing no pointers to additional storage.  This
00117  * allows the client to free this storage directly if its allocation
00118  * pool supports freeing (See the discussion under BS_Create below).
00119  *
00120  *
00121  *
00122  * Types
00123  * =====
00124  *
00125  *
00126  * TYPE struct bs BS
00127  *
00128  *     This is the client visible type of a BS.  It has no client
00129  *     visible fields.
00130  *
00131  *
00132  * TYPE BS_ELT
00133  *
00134  *      This is the type of an element of a BS.  It is a numeric type
00135  *      with the range 0..INT_MAX-1
00136  *
00137  *
00138  * Creation, Clearing, and Freeing
00139  * ===============================
00140  *
00141  *
00142  * BS *BS_Create( BS_ELT size, MEM_POOL *pool )
00143  *
00144  *     Creates and returns a new BS capable of holding (without
00145  *     expansion) any set of integers in the range 0 through size - 1.
00146  *     'Size' must be nonnegative or an error is caused.  The newly
00147  *     created BS is uninitialized, and may contain any of the
00148  *     possible sets.  'Pool' is used to allocate the space for the
00149  *     set.  Storage for the space is "flat", that is the set is
00150  *     allocated as a single array and contains no pointers to any
00151  *     additionally allocated memory.  The client is thus free to free
00152  *     the BS directly (if 'pool' supports this.)  (the allocated size
00153  *     may be obtained from BS_Alloc_Size).
00154  *
00155  *
00156  * size_t BS_Size_Alloc_Size( BS_ELT size )
00157  *
00158  *     Returns the number of bytes which would be required to allocate
00159  *     a set of 'size' size, i.e., the minimum number of bytes required
00160  *     to hold a set containing the elements 0 through size - 1.
00161  *
00162  *
00163  * size_t BS_Alloc_Size( BS *set )
00164  *
00165  *     Returns the number of bytes used to allocate the 'set'.
00166  *
00167  *
00168  * BS *BS_ClearD( BS *set )
00169  *
00170  *     Destructive clear operation.  After this 'set' will be empty.
00171  *     However, this does not change the allocated size of the set (it
00172  *     will still be able to contain the same members that it could
00173  *     before it was cleared without expansion.)
00174  *
00175  *
00176  * BS *BS_Create_Empty( BS_ELT size, MEM_POOL *pool )
00177  *
00178  *     Create an empty set large enough to hold the element 'size' - 1
00179  *     without expansion.  Equivalent to
00180  *
00181  *         BS_ClearD( BS_Create( size ), pool )
00182  *
00183  *
00184  * BS *BS_ResizeD( BS* set, BS_ELT new_size, MEM_POOL *pool )
00185  *
00186  *     Resize the set to be large enough to hold element 'new_size' - 1
00187  *     without expansion.  Similar to creating an empty set of the
00188  *     new_size, and then copying the set to it.
00189  *
00190  *
00191  * BS *BS_Range( BS_ELT low, BS_ELT high, MEM_POOL *pool )
00192  * BS *BS_RangeD( BS* set, BS_ELT low, BS_ELT high, MEM_POOL *pool )
00193  *
00194  *     Returns a set whose members are 'low' ... 'high'.  Both 'low'
00195  *     and the size of the range must be nonnegative or an error is
00196  *     caused.  I.e., 'low' >= 0 and ('high' - 'low' + 1) >= 0.  Note
00197  *     that 'high' may be -1 if 'low' is 0.
00198  *
00199  *
00200  * BS *BS_Singleton( BS_ELT element, MEM_POOL *pool )
00201  * BS *BS_SingletonD( BS *set, BS_ELT element, MEM_POOL *pool )
00202  *
00203  *     Returns a set with 'element' as its sole member.
00204  *
00205  *
00206  * BS *BS_Universe( BS_ELT size, MEM_POOL *pool )
00207  * BS *BS_UniverseD( BS *set, BS_ELT size, MEM_POOL *pool )
00208  *
00209  *     Returns a set containing 0...'size' - 1.  'Size' must be
00210  *     nonnegative or an error is caused.
00211  *
00212  *
00213  *
00214  * Copying
00215  * =======
00216  *
00217  *
00218  * BS *BS_Copy( BS *set, MEM_POOL *pool )
00219  * BS *BS_CopyD( BS *set1, BS *set2, MEM_POOL *pool )
00220  *
00221  *     Returns an exact copy of set.  Note that for BS_CopyD, if storage is
00222  *     allocated it will be the same as the storage actually allocated to
00223  *     set2, regardless of the current size of set2.  Thus the following
00224  *     sequence:
00225  *
00226  *         BS *set1, set2;
00227  *         set1 = BS_Create( 32, pool );
00228  *         set2 = BS_Create( 1024, pool );
00229  *         set2 = BS_ClearD( set2 );
00230  *         set1 = BS_CopyD( set1, set2, pool );
00231  *
00232  *     will result in set1 being grown to be large enough to contain
00233  *     the integer 1023, even though it will be empty.
00234  *
00235  *
00236  * Set Operations
00237  * ==============
00238  *
00239  *
00240  * BS_ELT BS_Choose( BS *set )
00241  *
00242  *     Returns some element of 'set', if 'set' is nonempty.  Else rerturns
00243  *     BS_CHOOSE_FAILURE.  In fact, this is defined so that it always
00244  *     returns the least element of the set.
00245  *
00246  *
00247  * BS_ELT BS_Intersection_Choose( BS *set1, BS *set2 )
00248  *
00249  *     Returns some element of the intersection of 'set1' and 'set2', if
00250  *     this intersection is nonempty.  Else rerturns BS_CHOOSE_FAILURE.
00251  *     In fact, this is defined so that it always returns the least
00252  *     element of the set.
00253  *
00254  *
00255  * BS_ELT BS_Choose_Range( BS *set, BS_ELT low, BS_ELT high )
00256  *
00257  *     Returns some element of 'set' intersection {low...high} if
00258  *     there is one.  Else returns BS_CHOOSE_FAILURE.  Both 'low' and
00259  *     the size of the range must be nonnegative or an error is
00260  *     caused.  I.e., 'low' >= 0 and ('high' - 'low' + 1) >= 0.  Note
00261  *     that 'high' may be -1 if 'low' is 0.  As with the _Choose
00262  *     function, always returns the last element of the set that's in
00263  *     range.
00264  *
00265  *
00266  * CONST BS_ELT BS_CHOOSE_FAILURE
00267  *
00268  *     A special value that BS_Choose and BS_Choose_Range return when they
00269  *     are unable to choose an element.
00270  *
00271  *
00272  * BS *BS_Difference( BS *set1, BS *set2, MEM_POOL *pool )
00273  * BS *BS_DifferenceD( BS *set1, BS *set2 )
00274  *
00275  *     Returns { x : member( x, 'set1' ) & ~ member( x, 'set2' ) }.
00276  *
00277  *
00278  * BS *BS_Difference1( BS *set, BS_ELT x, MEM_POOL *pool )
00279  * BS *BS_Difference1D( BS *set, BS_ELT x )
00280  *
00281  *     Returns { y : member( y , set ) & ~ ( y = x ) }.  X must be
00282  *     nonnegative or an error is caused.
00283  *
00284  *
00285  * BS *BS_Intersection( BS *set1, BS *set2, MEM_POOL *pool )
00286  * BS *BS_IntersectionD( BS *set1, BS *set2 )
00287  * BS *BS_IntersectionR( BS *result, BS *set1, BS *set2 )
00288  *
00289  *     Returns the intersection of 'set1' and 'set2'.
00290  *
00291  *
00292  * BS_ELT BS_Size( BS *set )
00293  *
00294  *     Returns the cardinality of 'set'.
00295  *
00296  *
00297  * BS *BS_Union( BS *set1, BS *set2, MEM_POOL *pool )
00298  * BS *BS_UnionD( BS *set1, BS *set2, MEM_POOL *pool )
00299  * BS *BS_UnionR( BS *result, BS *set1, BS *set2, MEM_POOL *pool )
00300  *
00301  *     Returns the union of set1 and set2.
00302  *
00303  *
00304  * BS *BS_Union1( BS *set, BS_ELT x, MEM_POOL *pool )
00305  * BS *BS_Union1D( BS *set, BS_ELT x, MEM_POOL *pool )
00306  *
00307  *     Returns set union { x }.  X must be nonnegative or an error is caused.
00308  *
00309  *
00310  * BS* BS_UnionD_Intersection( BS* set1, BS* set2, BS* set3, MEM_POOL* pool )
00311  *
00312  *      Destructively unions into set1 the intersection of set2 and set3,
00313  *      growing it if necessary in the given pool.
00314  *      
00315  *
00316  * BS *BS_2_1_Minus_3_Or_R(BS *result,BS *set1,BS *set2,BS *set3, MEM_POOL *pool)
00317  *
00318  *      Returns result = ~set1 & set2 | set3
00319  *
00320  *
00321  * BS *BS_3_2_Minus_1_Or_D(BS *set1,BS *set2,BS *set3, MEM_POOL *pool)
00322  *
00323  *      Returns set1 = ~set2 & set3 | set1
00324  *
00325  *
00326  * BS *BS_3_2_Minus_4_Or_1_Or_D(BS *set1,BS *set2,BS *set3, BS *set4, 
00327                             MEM_POOL *pool)
00328  *
00329  *      Returns set1 |= (~set2 & set3) | set4
00330  *
00331  *
00332  * BS *BS_3_2_Minus_4_Or_5_Or_1_Or_D(BS *set1,BS *set2,BS *set3, 
00333                                BS *set4, BS *set5, MEM_POOL *pool)
00334  *
00335  *      Returns set1 |= (~set2 & set3) | set4 | set5
00336  *
00337  *
00338  * BS *BS_2_1_Minus_3_Or_4_And_5_And_6_And_R( BS *result, BS *set1, BS *set2, BS *set3,
00339  *                                               BS *set4, BS *set5, BS *set6,
00340  *                                   MEM_POOL *pool)
00341  *
00342  *      Returns result = (~set1 & set2 | set3) & set4 & set5 & set6
00343  *
00344  *
00345  * BS *BS_2_1_Minus_3_Or_4_And_R( BS *result, BS *set1, BS *set2, BS *set3,
00346  *                                       BS *set4,
00347  *                                   MEM_POOL *pool)
00348  *
00349  *      Returns result = (~set1 & set2 | set3) & set4
00350  *
00351  *
00352  * BS *BS_1_Not_2_Or_3_Minus_4_And_R( BS *result, 
00353  *                              BS *set1, BS *set2, BS *set3, BS *set4,
00354  *                              MEM_POOL *pool )
00355  *
00356  *      Returns result = ((~set1) | set2) & (~set3) & set4
00357  *
00358  *
00359  * BS *BS_2_3_Or_1_Or_D(BS *set1,BS *set2,BS *set3, MEM_POOL *pool)
00360  *
00361  *      Returns set1 |= (set2 | set3)
00362  *
00363  *
00364  * BS *BS_1_2_Or_3_And_R(BS *result,BS *set1,BS *set2,BS *set3, MEM_POOL *pool)
00365  *
00366  *      Returns result = (set1 | set2) & set3
00367  *
00368  *
00369  * BS *BS_2_3_And_1_Or_D(BS *set1,BS *set2,BS *set3, MEM_POOL *pool)
00370  *
00371  *      Returns set1 = set1 | (set2 & set3)
00372  *
00373  *
00374  * BS *BS_3_Not_4_Or_2_And_1_Or_D(BS *set1,BS *set2,BS *set3,BS *set4, MEM_POOL *pool)
00375  *
00376  *      Returns set1 = set1 | (set2 * (~set3 | set4))
00377  *
00378  *
00379  * BS *BS_4_3_Minus_2_Not_Or_1_And_D(BS *set1,BS *set2,BS *set3,BS *set4, MEM_POOL *pool)
00380  *
00381  *      Returns set1 = set1 * (~set2 | (set4 * ~set3))
00382  *
00383  *
00384  * BS *BS_2_3_Minus_1_Or_D(BS *set1,BS *set2,BS *set3, MEM_POOL *pool)
00385  *
00386  *      Returns set1 = set1 | (set2 * ~set3)
00387  *
00388  *
00389  * BS *BS_2_3_Minus_4_Minus_1_Or_D(BS *set1,BS *set2,BS *set3,BS *set4, MEM_POOL *pool)
00390  *
00391  *      Returns set1 = set1 | (set2 * ~set3 * ~set4)
00392  *
00393  *
00394  *
00395  * Testing Sets
00396  * ============
00397  *
00398  *
00399  * BOOL BS_ContainsP( BS *set1, BS *set2 )
00400  *
00401  *     Returns TRUE iff every element of 'set2' is in 'set1'.  Else FALSE.
00402  *
00403  *
00404  * BOOL BS_EmptyP( BS *set )
00405  *
00406  *     Returns TRUE iff 'set' is empty.  Else FALSE.
00407  *
00408  *
00409  * BOOL BS_EqualP( BS *set1, BS *set2 )
00410  *
00411  *     Returns TRUE iff 'set1' has exactly the same members as 'set2'.
00412  *     Else FALSE.
00413  *
00414  *
00415  * BOOL BS_IntersectsP( BS *set1, BS *set2 )
00416  *
00417  *     Returns TRUE iff 'set1' and 'set2' have at least one member in
00418  *     common.  Else FALSE.
00419  *
00420  *
00421  * BOOL BS_MemberP( BS *set, BS_ELT x )
00422  *
00423  *     Returns TRUE iff 'x' is a member of 'set'.  Else FALSE.  'X'
00424  *     must be nonnegative or an error is caused.
00425  *
00426  * BOOL BS_Intersection_MemberP( BS *set1, BS *set2, BS_ELT x )
00427  *
00428  *     Returns TRUE iff 'x' is a member of the intersection of 'set1' and
00429  *     'set2'.
00430  *
00431  *
00432  * Looping Over Members
00433  * ====================
00434  *
00435  * BS_ELT BS_Choose_Next( BS *set, BS_ELT elt )
00436  *
00437  *     Returns the next element of 'set' after elt. If there is no such
00438  *     element, returns BS_CHOOSE_FAILURE.  This is useful for looping
00439  *     over the elements of a set.
00440  *
00441  *     Here's an example of how this is used:
00442  *
00443  *        BS_ELT elt;
00444  *        for ( elt = BS_Choose( set );
00445  *              elt != BS_CHOOSE_FAILURE;
00446  *              elt = BS_Choose_Next( set, elt ) )
00447  *        {
00448  *          elt is an element of the set
00449  *        }
00450  *
00451  * Looping over Members of an Intersection
00452  * =======================================
00453  *
00454  * BS_ELT BS_Intersection_Choose_Next(  BS *set1, BS *set2, BS_ELT x )
00455  *
00456  *      Returns the first member after 'x' of the intersection of 'set1'
00457  *      and 'set2' or BS_CHOOSE_FAILURE if the intersection is empty.
00458  *
00459  * Printing Sets
00460  * =============
00461  *
00462  *
00463  * void BS_Print( BS *set, FILE *f )
00464  *
00465  *     Prints 'set' on 'f'.  The type FILE is as defined in stdio.h.
00466  */
00467 
00468 #ifndef defs_INCLUDED
00469 #include "defs.h"
00470 #endif /* defs_INCLUDED */
00471 
00472 typedef struct bs BS;
00473 typedef INT32 BS_ELT;
00474 
00475 struct bv;
00476 
00477 
00478 /* Machine dependent definitions that will need to be changed for 64
00479  * bit implementation:
00480  */
00481 
00482 /* The basic word storage unit of a BS (MUST BE UNSIGNED)
00483  */
00484 #if defined(_MIPS_ISA) && _MIPS_ISA >= 3
00485 typedef mUINT64 BS_WORD;
00486 #define LOG2_BITS_PER_BS_WORD 6
00487 #else
00488 typedef mUINT32 BS_WORD;
00489 #define LOG2_BITS_PER_BS_WORD 5
00490 #endif
00491 
00492 typedef mUINT8  BS_BYTE;
00493 
00494 #define BITS_PER_BS_WORD    (sizeof(BS_WORD) * 8)
00495 #define BYTES_PER_BS_WORD   (sizeof(BS_WORD))
00496 
00497 /*
00498  *  bs_PBPW(x)      Product of (x * Bits Per Word)
00499  *  bs_QBPW(x)      Quotient of ( x / Bits Per Word)
00500  *  bs_RBPW(x)      Remainder of ( x / Bits Per Word)
00501  *  bs_PBPB(x)      Product of (x * Bits Per Byte)
00502  *  bs_QBPB(x)      Quotient of (x / Bits Per Byte)
00503  *  bs_RBPB(x)      Remainder of ( x / Bits Per Byte)
00504  *  bs_PBytesPW(x)  Product of (x * Bytes Per Word)
00505  */
00506 #define bs_PBPW(x)  ((BS_ELT) ((x) << LOG2_BITS_PER_BS_WORD))
00507 #define bs_QBPW(x)  ((BS_ELT) ((x) >> LOG2_BITS_PER_BS_WORD))
00508 #define bs_RBPW(x)  ((BS_ELT) ((x) & ((1 << LOG2_BITS_PER_BS_WORD) - 1)))
00509 #define bs_PBPB(x)  ((BS_ELT) ((x) << 3))
00510 #define bs_QBPB(x)  ((BS_ELT) ((x) >> 3))
00511 #define bs_RBPB(x)  ((BS_ELT) ((x) & 0x7))
00512 #define bs_PBytesPW(x)  ((BS_ELT) ((x) * BYTES_PER_BS_WORD))
00513 
00514 /* bs_ZEROS     a word of zeros
00515  * bs_ONES      a word of ones
00516  * bs_ONE       just 1
00517  */
00518 #define bs_ZEROS    ((BS_WORD) 0)
00519 #define bs_ONES     ((BS_WORD) ~0)
00520 #define bs_ONE      ((BS_WORD) 1)
00521 
00522 /* End of machine dependent part.
00523  */
00524 
00525 
00526 /* Representation of a bit set is a pointer to a sequence of the
00527  * words. The first of these words gives the length of the set in
00528  * total number of words available to hold members (does not include
00529  * the first word which holds the length.)
00530  *
00531  * The sets are essentially BYTE addressed, with word addressing used
00532  * only to improve the effeciency of operations that must look at the
00533  * whole set.  This has two advantages (on machines with effecient
00534  * byte addressing such as MIPS).  Firstly, it is an endian
00535  * independent representation.  Secondly it allows us to implement
00536  * very effecient Find_First_One and Population_Count operations at
00537  * the byte level as each only requires a table of 256 entries.
00538  *
00539  * x is an element of set if
00540  *
00541  *      1. x < BITS_PER_BS_WORD * BS_word_count(x), and
00542  *      2. BS_byte(set,x / 8) & (1 << x & 0x7) != bs_ZEROS
00543  */
00544 
00545 /* Basic access to BS's:
00546  *
00547  * BS_word_count(set)       Number of words allocated to hold elements
00548  *                          of set
00549  * BS_word(set,i)           i'th word of set
00550  * BS_byte(set,i)           i'th byte of set
00551  */
00552 #define BS_word_count(x) (*((BS_WORD *) x))
00553 #define BS_word(x,i)     (*(((BS_WORD *) x) + (i) + 1))
00554 #define BS_byte(x,i)     (*(((unsigned char *) x) + (i) + sizeof(BS_WORD)))
00555 
00556 
00557 /* Throw away a bit of address space to get a sane out of range
00558  * element.  This already doesn't matter and in the 64 bit environment
00559  * it really won't.
00560  */
00561 #define BS_MIN_ELT ((BS_ELT) 0)
00562 #define BS_MAX_ELT ((BS_ELT) UINT32_MAX)
00563 #define BS_CHOOSE_FAILURE ((BS_ELT) -1)
00564 
00565 extern BS *BS_Create( BS_ELT size, MEM_POOL *pool );
00566 extern size_t BS_Size_Alloc_Size( BS_ELT size );
00567 extern size_t BS_Alloc_Size( BS *set );
00568 extern BS *BS_ClearD( BS *set );
00569 extern BS *BS_Create_Empty( BS_ELT size, MEM_POOL *pool );
00570 extern BS *BS_ResizeD( BS* set, BS_ELT new_size, MEM_POOL *pool );
00571 extern BS *BS_Range( BS_ELT low, BS_ELT high, MEM_POOL *pool );
00572 extern BS *BS_RangeD( BS* set, BS_ELT low, BS_ELT high, MEM_POOL *pool );
00573 extern BS *BS_Singleton( BS_ELT element, MEM_POOL *pool );
00574 extern BS *BS_SingletonD( BS *set, BS_ELT element, MEM_POOL *pool );
00575 extern BS *BS_Universe( BS_ELT size, MEM_POOL *pool );
00576 extern BS *BS_UniverseD( BS *set, BS_ELT size, MEM_POOL *pool );
00577 extern BS *BS_Copy( BS *set, MEM_POOL *pool );
00578 extern BS *BS_CopyD( BS *set1, BS *set2, MEM_POOL *pool );
00579 extern BS_ELT BS_Choose( const BS *bs );
00580 extern BS_ELT BS_Intersection_Choose( BS *set1, BS *set2 );
00581 extern BS_ELT BS_Choose_Range( BS *set, BS_ELT low, BS_ELT high );
00582 extern BS *BS_Difference( BS *set1, BS *set2, MEM_POOL *pool );
00583 extern BS *BS_DifferenceD( BS *set1, BS *set2 );
00584 extern BS *BS_Difference1( BS *set, BS_ELT x, MEM_POOL *pool );
00585 extern BS *BS_Difference1D( BS *set, BS_ELT x );
00586 extern BS *BS_Intersection( BS *set1, BS *set2, MEM_POOL *pool );
00587 extern BS *BS_IntersectionD( BS *set1, BS *set2 );
00588 extern BS *BS_IntersectionR(BS* result, const BS *set1, const BS *set2);
00589 extern BS_ELT BS_Size( BS *set );
00590 extern BS *BS_Union( BS *set1, BS *set2, MEM_POOL *pool );
00591 extern BS *BS_UnionD( BS *set1, BS *set2, MEM_POOL *pool );
00592 extern BS *BS_UnionR( BS *result, BS *set1, BS *set2, MEM_POOL *pool );
00593 extern BS *BS_Union1( BS *set, BS_ELT x, MEM_POOL *pool );
00594 extern BS* BS_UnionD_Intersection( BS* set1, BS* set2, BS* set3,
00595                                    MEM_POOL *pool );
00596 extern BS *BS_Union1D( BS *set, BS_ELT x, MEM_POOL *pool );
00597 
00598 extern BS *BS_2_1_Minus_3_Or_R( BS *result, const BS *set1, const BS *set2,
00599                         const BS *set3, MEM_POOL *pool );
00600 extern BS *BS_3_2_Minus_1_Or_D( BS *set1, const BS *set2,
00601                         const BS *set3, MEM_POOL *pool );
00602 extern BS *BS_2_3_Or_1_Or_D( BS *set1, const BS *set2, const BS *set3,
00603                           MEM_POOL *pool );
00604 extern BS *BS_1_2_Or_3_And_R( BS *result, const BS *set1, const BS *set2,
00605                         const BS *set3, MEM_POOL *pool );
00606 extern BS *BS_2_3_And_1_Or_D(  BS *set1, const BS *set2,
00607                         const BS *set3, MEM_POOL *pool );
00608 extern BS *BS_1_Not_2_Or_3_Minus_4_And_R( BS *result, const BS *set1,
00609                         const BS *set2, const BS *set3, const BS *set4,
00610                         MEM_POOL *pool );
00611 
00612 extern BS *BS_2_1_Minus_3_Or_4_And_5_And_6_And_R( BS *result, const BS *set1,
00613                         const BS *set2, const BS *set3, const BS *set4,
00614                         const BS *set5, const BS *set6, MEM_POOL *pool);
00615 extern BS *BS_2_1_Minus_3_Or_4_And_R( BS *result, const BS *set1,
00616                         const BS *set2, const BS *set3, const BS *set4,
00617                         MEM_POOL *pool);
00618 extern BS *BS_3_2_Minus_4_Or_1_Or_D( BS *set1, const BS *set2,
00619                         const BS *set3, const BS *set4, MEM_POOL *pool);
00620 extern BS *BS_3_2_Minus_4_Or_5_Or_1_Or_D( BS *set1, const BS *set2, 
00621                         const BS *set3, const BS *set4, const BS *set5,
00622                         MEM_POOL *pool );
00623 extern BS *BS_3_Not_4_Or_2_And_1_Or_D( BS *result, const BS *set1,
00624                         const BS *set2, const BS *set3, MEM_POOL *pool);
00625 extern BS *BS_4_3_Minus_2_Not_Or_1_And_D(BS *result, const BS *set1,
00626                         const BS *set2, const BS *set3, MEM_POOL *pool);
00627 extern BS *BS_2_3_Minus_1_Or_D(BS *result, const BS *set1,
00628                         const BS *set2, MEM_POOL *pool);
00629 extern BS *BS_2_3_Minus_4_Minus_1_Or_D(BS *result, const BS *set1,
00630                         const BS *set2, const BS *set3, MEM_POOL *pool);
00631 extern BOOL BS_ContainsP( BS *set1, BS *set2 );
00632 extern BOOL BS_EmptyP( BS *set );
00633 extern BOOL BS_EqualP( BS *set1, BS *set2 );
00634 extern BOOL BS_IntersectsP( BS *set1, BS *set2 );
00635 extern BOOL BS_MemberP( BS *set, BS_ELT x );
00636 extern BOOL BS_Intersection_MemberP( BS *set1, BS *set2, BS_ELT x );
00637 extern BS_ELT BS_Choose_Next( const BS *set, BS_ELT elt);
00638 extern BS_ELT BS_Intersection_Choose_Next(BS *set1, BS *set2, BS_ELT elt);
00639 
00640 /* FBS -- fixed-size bitset implementation.
00641     Fixed size bitsets are faster because no implicit reallocation
00642     is required.   For debugging, a slower implementation that
00643     verifies the range of x is in bitset.c.  
00644 */
00645 extern BOOL FBS_MemberP_Validate(BS *set, BS_ELT x);
00646 extern void FBS_Union1D_Validate(BS *set, BS_ELT x);
00647 
00648 #ifdef Is_True_On
00649 #define FBS_MemberP(set, x)  FBS_MemberP_Validate(set, x)
00650 #define FBS_Union1D(set, x)  FBS_Union1D_Validate(set, x)
00651 #else
00652 #define FBS_MemberP(set, x)  (BS_byte(set,bs_QBPB(x)) & (bs_ONE << bs_RBPB(x)))
00653 #define FBS_Union1D(set, x)  (BS_byte(set,bs_QBPB(x)) |= bs_ONE << bs_RBPB(x))
00654 #endif
00655 
00656 extern void BS_Print( BS *set, FILE *f );
00657 
00658 #ifdef __cplusplus
00659 }
00660 #endif
00661 #endif /* bitset_INCLUDED */
00662 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines