utility.h

来自「C++编写的机器学习算法 Lemga is a C++ package whi」· C头文件 代码 · 共 50 行

H
50
字号
// -*- C++ -*-#ifndef __LEMGA_UTILITY_H__#define __LEMGA_UTILITY_H__/** @file *  @brief Some utility functions. * *  $Id: utility.h 2529 2005-12-27 08:33:18Z ling $ */#include <vector>/// Gray code: start from all 0's, and iteratively go through all numberstemplate<class N>bool gray_next (std::vector<N>& v, typename std::vector<N>::size_type& p) {    typename std::vector<N>::size_type n = v.size();    assert(n > 0);    // by default we alter the last bit    p = n - 1;    bool more = true;    // find the largest n such that v[n] == 1    while (--n && v[n] == 0) /* empty */;    if (n > 0) {        typename std::vector<N>::size_type j = n;        bool xor_sum = true;        while (n--)            xor_sum = xor_sum ^ (v[n] != 0);        if (xor_sum) p = j - 1;    } else if (v[0] != 0) {        p = 0; more = false;    }    v[p] = (v[p] == 0);    return more;}template<class N>bool gray_next (std::vector<N>& v) {    typename std::vector<N>::size_type p;    return gray_next(v, p);}#ifdef  __UTILITY_H__#warning "This header file may conflict with another `utility.h' file."#endif#define __UTILITY_H__#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?