25 #ifndef _GATB_CORE_TOOLS_MATH_INTEGER_HPP_
26 #define _GATB_CORE_TOOLS_MATH_INTEGER_HPP_
31 #include <boost/variant.hpp>
59 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
64 typedef boost::variant<T1,T2,T3,T4,T5>
Type;
77 int p = (kmer_len+31)/32;
83 else { std::cerr <<
"Not supported kmer length in Integer initialization";
exit(1); }
87 int p = (kmer.size()+31)/32;
89 else if(p <=
PREC_2)
v = T2(kmer);
90 else if(p <=
PREC_3)
v = T3(kmer);
91 else if(p <=
PREC_4)
v = T4(kmer);
92 else if(p <=
PREC_5)
v = T5(kmer);
93 else { std::cerr <<
"Not supported kmer length in Integer initialization";
exit(1); }
96 IntegerTemplate(
const std::string::const_iterator&
a,
const std::string::const_iterator&
b) {
103 else { std::cerr <<
"Not supported kmer length in Integer initialization";
exit(1); }
134 const char*
getName ()
const {
return boost::apply_visitor (Integer_name(), *(*
this)); }
139 const size_t getSize ()
const {
return boost::apply_visitor (Integer_size(), *(*
this)); }
262 u_int8_t
operator[] (
size_t idx)
const {
return boost::apply_visitor (Integer_value_at(idx), *(*
this)); }
275 std::string toString (
size_t sizeKmer)
const {
return boost::apply_visitor (Integer_toString(sizeKmer), *(*
this)); }
290 const U&
get ()
const {
return * boost::get<U>(&
v); }
299 u_int64_t
oahash()
const {
return boost::apply_visitor (Integer_oahash(), *(*
this)); }
305 template<
typename T,
typename U>
void operator() (
T& newl, U& origl)
const {
306 int orig_precision = origl.getSize()/64;
307 uint64_t* orig_guts = origl.GetGuts();
309 int new_precision = newl.getSize()/64;
310 uint64_t* new_guts = newl.GetGuts();
312 std::copy(orig_guts, orig_guts+
std::min(orig_precision, new_precision), new_guts);
313 int partial_part_bits = 2*(
kmer_len%32);
314 if(partial_part_bits > 0) {
316 new_guts[new_precision-1] &=
mask;
322 template<
typename T> u_int64_t
operator() (
const T&
a)
const {
return a.oahash(); }};
324 struct Pointer :
public boost::static_visitor<void*> {
328 template<
typename T>
const char*
operator() (
const T&
a)
const {
return a.getName(); }};
331 template<
typename T>
const size_t operator() (
const T&
a)
const {
return a.getSize(); }};
343 struct Integer_or :
public boost::static_visitor<IntegerTemplate> {
348 struct Integer_xor :
public boost::static_visitor<IntegerTemplate> {
353 struct Integer_and :
public boost::static_visitor<IntegerTemplate> {
360 template<
typename T,
typename U>
bool operator() (
const T&
a,
const U&
b)
const {
return false; }
365 template<
typename T,
typename U>
bool operator() (
const T&
a,
const U&
b)
const {
return false; }
370 template<
typename T,
typename U>
bool operator() (
const T&
a,
const U&
b)
const {
return false; }
375 template<
typename T,
typename U>
void operator() (
T&
a,
const U&
b)
const { }
380 template<
typename T,
typename U>
void operator() (
T&
a,
const U&
b)
const { }
386 template<
typename Result,
typename Arg>
387 struct Visitor :
public boost::static_visitor<Result>
428 #define INTEGER_TYPES LargeInt<PREC_1>,LargeInt<PREC_2>,LargeInt<PREC_3>,LargeInt<PREC_4>,LargeInt<PREC_5>
Class that manages large integers.
Class for large integers calculus.
const char * getName() const
Get the name of the class used by the variant (ie.
const U & get() const
Get the value of the IntegerTemplate object as a U type, U being one of the T1,T2,...
friend std::ostream & operator<<(std::ostream &s, const IntegerTemplate &a)
Output stream operator for the IntegerTemplate class.
u_int8_t operator[](size_t idx) const
Operator[] access the ith nucleotide in the given integer.
friend bool operator<(const IntegerTemplate &a, const IntegerTemplate &b)
Operator <.
friend bool operator!=(const IntegerTemplate &a, const IntegerTemplate &b)
Operator !=.
friend IntegerTemplate revcomp(const IntegerTemplate &a, size_t sizeKmer)
Get the reverse complement of a kmer encoded as an IntegerTemplate object.
void operator^=(const IntegerTemplate &a)
Operator ^=.
IntegerTemplate(const T &t)
Construct from a different size IntegerTemplate Will clip (or add) extra nucs on the LEFT of the stri...
friend IntegerTemplate operator&(const IntegerTemplate &a, const IntegerTemplate &b)
Operator &.
friend IntegerTemplate operator^(const IntegerTemplate &a, const IntegerTemplate &b)
Operator ^.
friend bool operator==(const IntegerTemplate &a, const IntegerTemplate &b)
Operator ==.
friend IntegerTemplate operator+(const IntegerTemplate &a, const IntegerTemplate &b)
Operator +.
const size_t getSize() const
Get the size of an instance of the class used by the variant (ie.
IntegerTemplate(int kmer_len, uint64_t n)
void operator+=(const IntegerTemplate &a)
Operator +=.
friend IntegerTemplate operator/(const IntegerTemplate &a, const u_int32_t &c)
Operator /.
friend IntegerTemplate operator<<(const IntegerTemplate &a, const int &c)
Operator <<.
IntegerTemplate(const std::string::const_iterator &a, const std::string::const_iterator &b)
friend IntegerTemplate operator-(const IntegerTemplate &a, const IntegerTemplate &b)
Operator -.
friend bool operator<=(const IntegerTemplate &a, const IntegerTemplate &b)
Operator <=.
IntegerTemplate(const std::string &kmer)
IntegerTemplate & operator=(const T &t)
Affectation operator.
friend IntegerTemplate operator|(const IntegerTemplate &a, const IntegerTemplate &b)
Operator |.
friend u_int32_t operator%(const IntegerTemplate &a, const u_int32_t &c)
Operator %.
friend IntegerTemplate operator~(const IntegerTemplate &a)
Operator ~.
boost::variant< T1, T2, T3, T4, T5 > Type
friend IntegerTemplate operator>>(const IntegerTemplate &a, const int &c)
Operator >>
std::string toString(size_t sizeKmer) const
Get an ASCII string representation of a kmer encoded as a IntegerTemplate object.
void * getPointer()
Get pointer to the actual data - used for EMPHF.
u_int64_t oahash() const
Get a hash value on 64 bits for a given IntegerTemplate object.
unsigned int
A callback function used to compare two keys in a database.
IntegerTemplate< LargeInt< 1 >, LargeInt< 2 >, LargeInt< 4 >, LargeInt< 8 >, LargeInt< 16 > > TKmer
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
unsigned __int64 uint64_t
IntegerTemplate operator()(const T &a, const T &b) const
IntegerTemplate operator()(const T &a)
IntegerTemplate operator()(const T &a) const
Integer_div(const u_int32_t &c)
bool operator()(const T &a, const T &b) const
bool operator()(const T &a, const T &b) const
bool operator()(const T &a, const T &b) const
IntegerTemplate operator()(const T &a, const T &b) const
u_int32_t operator()(const T &a) const
Integer_mod(const u_int32_t &c)
IntegerTemplate operator()(const T &a) const
Integer_mult(const int &c)
const char * operator()(const T &a) const
u_int64_t operator()(const T &a) const
IntegerTemplate operator()(const T &a, const T &b) const
IntegerTemplate operator()(const T &a, const T &b) const
void operator()(T &a, const T &b) const
IntegerTemplate operator()(const T &a) const
Integer_revomp(const size_t &c)
Integer_shiftLeft(const int &c)
IntegerTemplate operator()(const T &a) const
Integer_shiftRight(const int &c)
IntegerTemplate operator()(const T &a) const
const size_t operator()(const T &a) const
Integer_toString(size_t c)
std::string operator()(const T &a) const
u_int8_t operator()(const T &a) const
Integer_value_at(size_t idx)
IntegerTemplate operator()(const T &a, const T &b) const
void operator()(T &a, const T &b) const
void * operator()(T &a) const
void operator()(T &newl, U &origl) const