Main Page   Modules   Compound List   File List   Compound Members   File Members  

bit_array.h

Go to the documentation of this file.
00001 
00014 /* This library is free software; you can redistribute it and/or
00015    modify it under the terms of the GNU Lesser General Public
00016    License as published by the Free Software Foundation; either
00017    version 2.1 of the License, or (at your option) any later version.
00018 
00019    This library is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022    Lesser General Public License for more details.
00023 
00024    You should have received a copy of the GNU Lesser General Public
00025    License along with this library; if not, write to the Free Software
00026    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 */
00028 
00029 #ifndef _GAN_BIT_ARRAY_H
00030 #define _GAN_BIT_ARRAY_H
00031 
00032 #include <stdio.h>
00033 #include <gandalf/common/misc_defs.h>
00034 #include <gandalf/common/allocate.h>
00035 #include <gandalf/common/memory_stack.h>
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00052 
00053 typedef gan_ui64 Gan_BitWord;
00054 #define GAN_BITWORD_SIZE 64
00055 #define GAN_BITWORD_FULL (gan_ui64) GAN_UI64_MAX
00056 #define GAN_MSB_SET (gan_ui64) 0x8000000000000000 /*(1<<63)*/
00057 #define GAN_LSB_SET (gan_ui64) 1
00058 
00059 
00063 typedef enum {GAN_WORD_ALIGNMENT, GAN_BYTE_ALIGNMENT, GAN_BIT_ALIGNMENT}
00064    Gan_Alignment;
00065 
00067 typedef struct Gan_BitArray
00068 {
00069    Gan_BitWord *data;
00070    unsigned int no_bits;
00071    unsigned int no_words;
00072 
00073    /* allocated number of words */
00074    unsigned int words_alloc;
00075 
00076    /* whether the data array was dynamically allocated */
00077    Gan_Bool data_alloc;
00078 
00079    /* memory stack pointer or NULL */
00080    Gan_MemoryStack *memory_stack;
00081 
00082    /* whether this structure was dynamically allocated */
00083    Gan_Bool alloc;
00084 } Gan_BitArray;
00085 
00086 Gan_BitArray *gan_bit_array_form_data ( Gan_BitArray *ba,
00087                                         Gan_BitWord *data, unsigned data_words,
00088                                         unsigned int no_bits );
00089 Gan_BitArray *gan_bit_array_ms_form ( Gan_MemoryStack *ms, Gan_BitArray *ba,
00090                                       unsigned int no_bits );
00091 Gan_Bool gan_bit_array_set_size ( Gan_BitArray *ba, unsigned int no_bits );
00092 void     gan_bit_array_free    ( Gan_BitArray *ba );
00093 void     gan_bit_array_free_va ( Gan_BitArray *ba, ... );
00094 
00095 /* Logic Functions */
00096 
00097 Gan_Bool      gan_bit_array_invert_i ( Gan_BitArray *ba );
00098 Gan_BitArray *gan_bit_array_invert_s ( Gan_BitArray *ba );
00099 Gan_Bool gan_bit_array_and_i    ( Gan_BitArray *ba_dst, Gan_BitArray *ba );
00100 Gan_Bool gan_bit_array_nand_i   ( Gan_BitArray *ba_dst, Gan_BitArray *ba );
00101 Gan_Bool gan_bit_array_or_i     ( Gan_BitArray *ba_dst, Gan_BitArray *ba );
00102 Gan_Bool gan_bit_array_eor_i    ( Gan_BitArray *ba_dst, Gan_BitArray *ba );
00103 Gan_Bool gan_bit_array_andnot_i ( Gan_BitArray *ba_dst, Gan_BitArray *ba );
00104 Gan_BitArray *gan_bit_array_and_s    ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00105 Gan_BitArray *gan_bit_array_nand_s   ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00106 Gan_BitArray *gan_bit_array_or_s     ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00107 Gan_BitArray *gan_bit_array_eor_s    ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00108 Gan_BitArray *gan_bit_array_andnot_s ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00109 
00110 /* insert part of src bit array into dst bit array */
00111 Gan_Bool gan_bit_array_insert ( Gan_BitArray *source, unsigned int offset_s,
00112                                 Gan_BitArray *dest,   unsigned int offset_d,
00113                                 unsigned int no_bits );
00114 
00115 /* set all bits in a bit array */
00116 Gan_Bool gan_bit_array_fill ( Gan_BitArray *ba, Gan_Bool val );
00117 
00118 /* copy one bit array to another */
00119 Gan_Bool      gan_bit_array_copy_q ( Gan_BitArray *ba_source,
00120                                      Gan_BitArray *ba_dest );
00121 Gan_BitArray *gan_bit_array_copy_s ( Gan_BitArray *ba_source );
00122 
00123 Gan_Bool      gan_bit_array_expand_q ( Gan_BitArray *ba,
00124                                        Gan_BitArray *ref_ba,
00125                                        Gan_BitArray *exp_ba );
00126 Gan_BitArray *gan_bit_array_expand_s ( Gan_BitArray *ba,
00127                                        Gan_BitArray *ref_ba );
00128 
00129 /* fill part of a bit array */
00130 Gan_Bool gan_bit_array_fill_part ( Gan_BitArray *ba, unsigned int offset,
00131                                    unsigned int no_bits, Gan_Bool val );
00132 
00133 /* invert part of a bit array */
00134 Gan_Bool gan_bit_array_invert_part ( Gan_BitArray *ba, unsigned int offset,
00135                                      unsigned int no_bits );
00136 
00137 /* print bit array in ASCII to file */
00138 void gan_bit_array_fprint ( FILE *fp, Gan_BitArray *ba, int indent );
00139 
00143 unsigned GAN_NO_BITWORDS ( unsigned no_bits );
00144 
00148 Gan_BitArray *
00149  gan_bit_array_form ( Gan_BitArray *ba, unsigned int no_bits );
00150 
00154 Gan_BitArray *gan_bit_array_alloc ( unsigned int no_bits );
00155 
00159 Gan_BitArray *gan_bit_array_ms_malloc ( unsigned int no_bits );
00160 
00167 Gan_Bool gan_bit_array_print ( Gan_BitArray *bit_array, int indent );
00168 
00172 Gan_Bool gan_bit_array_set_bit ( Gan_BitArray *bit_array, int pos );
00173 
00177 Gan_Bool gan_bit_array_get_bit ( Gan_BitArray *bit_array, int pos );
00178 
00182 Gan_Bool gan_bit_array_clear_bit ( Gan_BitArray *bit_array, int pos );
00183 
00187 Gan_Bool
00188  gan_bit_array_twiddle_bit ( Gan_BitArray *bit_array, int pos, Gan_Bool val );
00189 
00190 
00194 Gan_Bool
00195  gan_bit_array_invert_bit ( Gan_BitArray *bit_array, int pos );
00196 
00205 #ifdef __cplusplus
00206 }
00207 #endif
00208 
00209 #endif /* #ifndef _GAN_BIT_ARRAY_H */

Generated on Mon Oct 13 16:14:32 2003 by doxygen1.3-rc1