utility.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef __LEMGA_UTILITY_H__
00003 #define __LEMGA_UTILITY_H__
00004 
00011 #include <vector>
00012 #include "object.h"
00013 
00017 bool ldivide (std::vector<std::vector<REAL> >& A,
00018               const std::vector<REAL>& b, std::vector<REAL>& x);
00019 
00021 template<class N>
00022 bool gray_next (std::vector<N>& v, typename std::vector<N>::size_type& p) {
00023     typename std::vector<N>::size_type n = v.size();
00024     assert(n > 0);
00025 
00026     // by default we alter the last bit
00027     p = n - 1;
00028     bool more = true;
00029 
00030     // find the largest n such that v[n] == 1
00031     while (--n && v[n] == 0) /* empty */;
00032 
00033     if (n > 0) {
00034         typename std::vector<N>::size_type j = n;
00035         bool xor_sum = true;
00036         while (n--)
00037             xor_sum = xor_sum ^ (v[n] != 0);
00038         if (xor_sum) p = j - 1;
00039     } else if (v[0] != 0) {
00040         p = 0; more = false;
00041     }
00042     v[p] = (v[p] == 0);
00043     return more;
00044 }
00045 
00046 template<class N>
00047 bool gray_next (std::vector<N>& v) {
00048     typename std::vector<N>::size_type p;
00049     return gray_next(v, p);
00050 }
00051 
00052 #ifdef  __UTILITY_H__
00053 #warning "This header file may conflict with another `utility.h' file."
00054 #endif
00055 #define __UTILITY_H__
00056 #endif

Generated on Wed Nov 8 08:15:22 2006 for LEMGA by  doxygen 1.4.6