📄 utility.h
字号:
// -*- 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -