⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 permuter.h

📁 粗糙集应用软件
💻 H
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Revisions.....:
//===================================================================

#ifndef __PERMUTER_H__
#define __PERMUTER_H__

#include <copyright.h>

#include <kernel/basic/vector.h>

//-------------------------------------------------------------------
// Class.........: Permuter
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Helper class for creating a permutation of the
//                 index set {0, ..., n - 1} such that the
//                 permutation is sorted according to a given vector
//                 of sorting keys.
// Comments......:
// Revisions.....:
//===================================================================

template <class T>
class Permuter {
private:

	//- STL helper class...............................................
	struct IndexComparator {
	private:

		//- Comparison keys..............................................
		const Vector(T) *keys_;

		//- Constructor..................................................
		IndexComparator() {keys_ = NULL;}

	public:

		//- Comparison operator..........................................
		bool operator()(int i, int j) const {
			return (*keys_)[i] < (*keys_)[j];
		}

		//- Constructor..................................................
		IndexComparator(const Vector(T) *keys) {keys_ = keys;}

	};

public:

	//- Constructors/destructor........................................
	Permuter() {};
	~Permuter() {};

	//- Methods........................................................
	bool Permute(const Vector(T) &keys, Vector(int) &permutation) const;

};

//-------------------------------------------------------------------
// Method........: Permute
// Author........:
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

template <class T>
inline bool Permuter<T>::Permute(const Vector(T) &keys, Vector(int) &permutation) const {

	if (!permutation.empty())
		permutation.erase(permutation.begin(), permutation.end());

	permutation.reserve(keys.size());

	int i;

	for (i = 0; i < keys.size(); i++)
		permutation.push_back(i);

	IndexComparator compare(&keys);

	std::sort(permutation.begin(), permutation.end(), compare);

	return true;

}

#endif

⌨️ 快捷键说明

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