Gk-arrays
Efficient read indexing
basic.h
00001 /* basics.h
00002 
00003    Code mostly inspired from original file written by Rodrigo Gonzalez.
00004 
00005    Copyright (C) 2005, Rodrigo Gonzalez, all rights reserved.
00006 
00007    Some preliminary stuff
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Lesser General Public
00011    License as published by the Free Software Foundation; either
00012    version 2.1 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Lesser General Public License for more details.
00018 
00019    You should have received a copy of the GNU Lesser General Public
00020    License along with this library; if not, write to the Free Software
00021    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 */
00024 
00025 
00026 #ifndef BASICSINCLUDED
00027 #define BASICSINCLUDED
00028 
00029 #include <limits>
00030 #ifdef HAVE_CONFIG_H
00031 #  include <config.h>
00032 #endif
00033 
00034 /*number of bits of a machine word */
00035 const size_t W = std::numeric_limits<u_int64_t>::digits;
00036 
00037 /* reads bit p from e */
00038 template <class T>
00039 bool bitget(const T * const e, const u_int64_t p) {
00040   return ((e[p/W] >> (p % W)) & u_int64_t(1));
00041 }
00042 
00043 /* sets bit p in e */
00044 template <class T>
00045 void bitset(T * const e, const u_int64_t p) {
00046   e[p/W] |= u_int64_t(1) << (p % W);
00047 }
00048 
00049 /* cleans bit p in e */
00050 template <class T>
00051 void bitclean(T * const e, const u_int64_t p) {
00052   e[p/W] &= ~(u_int64_t(1) << (p % W));
00053 }
00054 
00055 /* number of machine words requiered to represents e elements of length n */
00056 inline u_int64_t nb_digits(const u_int64_t &e, const u_int64_t &n) {
00057   return (e * n) / W + ((e * n) % W > 0);
00058 }
00059 
00060 #endif
00061 
00062 // Local Variables:
00063 // mode:c++
00064 // End:
 All Classes Functions