include/util/bitset/bmconst.h

Go to the documentation of this file.
00001 #ifndef BMCONST__H__INCLUDED__
00002 #define BMCONST__H__INCLUDED__
00003 /*
00004 Copyright(c) 2002-2009 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)
00005 
00006 Permission is hereby granted, free of charge, to any person 
00007 obtaining a copy of this software and associated documentation 
00008 files (the "Software"), to deal in the Software without restriction, 
00009 including without limitation the rights to use, copy, modify, merge, 
00010 publish, distribute, sublicense, and/or sell copies of the Software, 
00011 and to permit persons to whom the Software is furnished to do so, 
00012 subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included 
00015 in all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00018 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
00019 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00020 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
00021 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
00022 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
00023 OTHER DEALINGS IN THE SOFTWARE.
00024 
00025 For more information please visit:  http://bmagic.sourceforge.net
00026 
00027 */
00028 
00029 namespace bm
00030 {
00031 
00032 #if defined(_WIN32) || defined (_WIN64)
00033 
00034 typedef unsigned __int64 id64_t;
00035 
00036 #else
00037 
00038 typedef unsigned long long id64_t;
00039 
00040 #endif
00041 
00042 typedef unsigned int   id_t;
00043 typedef unsigned int   word_t;
00044 typedef unsigned short short_t;
00045 
00046 
00047 
00048 const unsigned id_max = 0xFFFFFFFF;
00049 
00050 // Data Block parameters
00051 
00052 const unsigned set_block_size  = 2048u;
00053 const unsigned set_block_shift = 16u;
00054 const unsigned set_block_mask  = 0xFFFFu;
00055 const unsigned set_blkblk_mask = 0xFFFFFFu;
00056 
00057 const unsigned set_block_plain_size = set_block_size / 32u;
00058 const unsigned set_block_plain_cnt = sizeof(bm::word_t) * 8u;
00059 
00060 // Word parameters
00061 
00062 const unsigned set_word_shift = 5u;
00063 const unsigned set_word_mask  = 0x1Fu;
00064 
00065 
00066 // GAP related parameters.
00067 
00068 typedef unsigned short gap_word_t;
00069 
00070 const unsigned gap_max_buff_len = 1280;
00071 const unsigned gap_max_bits = 65536;
00072 const unsigned gap_equiv_len = 
00073    (sizeof(bm::word_t) * bm::set_block_size) / sizeof(gap_word_t);
00074 const unsigned gap_levels = 4;
00075 const unsigned gap_max_level = bm::gap_levels - 1;
00076 
00077 
00078 // Block Array parameters
00079 
00080 const unsigned set_array_size = 256u;
00081 const unsigned set_array_shift = 8u;
00082 const unsigned set_array_mask  = 0xFFu;
00083 const unsigned set_total_blocks = (bm::set_array_size * bm::set_array_size);
00084 
00085 const unsigned bits_in_block = bm::set_block_size * sizeof(bm::word_t) * 8;
00086 const unsigned bits_in_array = bm::bits_in_block * bm::set_array_size;
00087 
00088 
00089 #ifdef BM64OPT
00090 
00091 typedef id64_t  wordop_t;
00092 const id64_t    all_bits_mask = 0xffffffffffffffff;
00093 
00094 # define DECLARE_TEMP_BLOCK(x)  bm::id64_t x[bm::set_block_size / 2]; 
00095 const unsigned set_block_size_op  = bm::set_block_size / 2;
00096 
00097 
00098 #else
00099 
00100 typedef word_t wordop_t;
00101 const word_t all_bits_mask = 0xffffffff;
00102 
00103 # define DECLARE_TEMP_BLOCK(x)  unsigned x[bm::set_block_size]; 
00104 const unsigned set_block_size_op  = bm::set_block_size;
00105 
00106 #endif
00107 
00108 
00109 
00110 /*!
00111    @brief Block allocation strategies.
00112    @ingroup bvector
00113 */
00114 enum strategy
00115 {
00116     BM_BIT = 0, //!< No GAP compression strategy. All new blocks are bit blocks.
00117     BM_GAP = 1  //!< GAP compression is ON.
00118 };
00119 
00120 
00121 template<bool T> struct DeBruijn_bit_position
00122 {
00123     static const unsigned _multiply[32];
00124 };
00125 
00126 template<bool T>
00127 const unsigned DeBruijn_bit_position<T>::_multiply[32] = { 
00128   0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 
00129   31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
00130 };
00131 
00132 /** Structure keeps index of first right 1 bit for every byte.  
00133     @ingroup bitfunc 
00134 */
00135 template<bool T> struct first_bit_table
00136 {
00137     static const char _idx[256];
00138 };
00139 
00140 template<bool T>
00141 const char first_bit_table<T>::_idx[256] = {
00142   -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
00143     4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
00144     5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
00145     5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
00146     6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
00147     6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
00148     6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
00149     6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
00150     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00151     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00152     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00153     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00154     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00155     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00156     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00157     7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00158 };
00159 
00160 //---------------------------------------------------------------------
00161 
00162 /** Structure to aid in counting bits
00163     table contains count of bits in 0-255 diapason of numbers
00164 
00165    @ingroup bitfunc
00166 */
00167 template<bool T> struct bit_count_table 
00168 {
00169   static const unsigned char _count[256];
00170 };
00171 
00172 template<bool T>
00173 const unsigned char bit_count_table<T>::_count[256] = {
00174     0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
00175     1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
00176     1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
00177     2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
00178     1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
00179     2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
00180     2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
00181     3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
00182 };
00183 
00184 
00185 } // namespace
00186 
00187 #endif
00188 
00189 
00190 

Generated on Sun Dec 6 22:15:47 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:20:49 2009 by modify_doxy.py rev. 173732