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_BitArray *gan_bit_array_and_s  ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00104 Gan_BitArray *gan_bit_array_nand_s ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00105 Gan_BitArray *gan_bit_array_or_s   ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00106 Gan_BitArray *gan_bit_array_eor_s  ( Gan_BitArray *ba1, Gan_BitArray *ba2 );
00107 
00108 /* insert part of src bit array into dst bit array */
00109 Gan_Bool gan_bit_array_insert ( Gan_BitArray *source, unsigned int offset_s,
00110                                 Gan_BitArray *dest,   unsigned int offset_d,
00111                                 unsigned int no_bits );
00112 
00113 /* set all bits in a bit array */
00114 Gan_Bool gan_bit_array_fill ( Gan_BitArray *ba, Gan_Bool val );
00115 
00116 /* copy one bit array to another */
00117 Gan_Bool      gan_bit_array_copy_q ( Gan_BitArray *ba_source,
00118                                      Gan_BitArray *ba_dest );
00119 Gan_BitArray *gan_bit_array_copy_s ( Gan_BitArray *ba_source );
00120 
00121 Gan_Bool      gan_bit_array_expand_q ( Gan_BitArray *ba,
00122                                        Gan_BitArray *ref_ba,
00123                                        Gan_BitArray *exp_ba );
00124 Gan_BitArray *gan_bit_array_expand_s ( Gan_BitArray *ba,
00125                                        Gan_BitArray *ref_ba );
00126 
00127 /* fill part of a bit array */
00128 Gan_Bool gan_bit_array_fill_part ( Gan_BitArray *ba, unsigned int offset,
00129                                    unsigned int no_bits, Gan_Bool val );
00130 
00131 /* invert part of a bit array */
00132 Gan_Bool gan_bit_array_invert_part ( Gan_BitArray *ba, unsigned int offset,
00133                                      unsigned int no_bits );
00134 
00135 /* print bit array in ASCII to file */
00136 void gan_bit_array_fprint ( FILE *fp, Gan_BitArray *ba, int indent );
00137 
00141 unsigned GAN_NO_BITWORDS ( unsigned no_bits );
00142 
00146 Gan_BitArray *
00147  gan_bit_array_form ( Gan_BitArray *ba, unsigned int no_bits );
00148 
00152 Gan_BitArray *gan_bit_array_alloc ( unsigned int no_bits );
00153 
00157 Gan_BitArray *gan_bit_array_ms_malloc ( unsigned int no_bits );
00158 
00165 Gan_Bool gan_bit_array_print ( Gan_BitArray *bit_array, int indent );
00166 
00170 Gan_Bool gan_bit_array_set_bit ( Gan_BitArray *bit_array, int pos );
00171 
00175 Gan_Bool gan_bit_array_get_bit ( Gan_BitArray *bit_array, int pos );
00176 
00180 Gan_Bool gan_bit_array_clear_bit ( Gan_BitArray *bit_array, int pos );
00181 
00185 Gan_Bool
00186  gan_bit_array_twiddle_bit ( Gan_BitArray *bit_array, int pos, Gan_Bool val );
00187 
00188 
00192 Gan_Bool
00193  gan_bit_array_invert_bit ( Gan_BitArray *bit_array, int pos );
00194 
00203 #ifdef __cplusplus
00204 }
00205 #endif
00206 
00207 #endif /* #ifndef _GAN_BIT_ARRAY_H */

Generated on Fri Mar 14 19:32:20 2003 by doxygen1.3-rc1