LINUX.ORG.RU

История изменений

Исправление thunar, (текущая версия) :

Вот что я хотел:

struct pool_t {

private:
	std::byte   *data;
	size_t       tk, v0, vk, vj; 

public:
	enum ord {row, col};

	//------------------------------------------------------------------//
	pool_t (std::byte* p, int nk, int nj, ord arg) : data(p) {
		switch (arg) {
			case ord::row:
			tk = sizeof(int) + sizeof(float)*nj;
			v0 = sizeof(int);
			vk = sizeof(int) + sizeof(float)*nj;
			vj = sizeof(float);
			return;
			case ord::col:
			tk = sizeof(int);
			v0 = sizeof(int)*nk;
			vk = sizeof(float);
			vj = sizeof(float)*nk;
			return;
		}
	}

	//------------------------------------------------------------------//
	void readpt
	(const int& k, const int& n, int& tag, float vec[]) {
		std::byte *ptag{data + tk*k}, *pvec{data + v0 + vk*k};
		
		tag = *reinterpret_cast<int*>(ptag);
		for (int j=0; j<n; ++j) {
			vec[j] = *reinterpret_cast<float*>(pvec + vj*j);
		}
	}

	//------------------------------------------------------------------//
	void writept
	(const int& k, const int& n, const int& tag, const float vec[]) {
		std::byte *ptag{data + tk*k}, *pvec{data + v0 + vk*k};
		
		*reinterpret_cast<int*>(ptag) = tag;
		for (int j=0; j<n; ++j) {
			*reinterpret_cast<float*>(pvec + vj*j) = vec[j];
		}
	}
};

Исправление thunar, :

Вот что я хотел:

struct pool_t {

private:
	char   *data;
	size_t  tk, v0, vk, vj; 

public:
	enum ord {row, col};

	//------------------------------------------------------------------//
	pool_t (char* p, int nk, int nj, ord arg) : data(p) {
		switch (arg) {
			case ord::row:
			tk = sizeof(int) + sizeof(float)*nj;
			v0 = sizeof(int);
			vk = sizeof(int) + sizeof(float)*nj;
			vj = sizeof(float);
			return;
			case ord::col:
			tk = sizeof(int);
			v0 = sizeof(int)*nk;
			vk = sizeof(float);
			vj = sizeof(float)*nk;
			return;
		}
	}

	//------------------------------------------------------------------//
	void readpt
	(const int& k, const int& n, int& tag, float vec[]) {
		char *ptag{data + tk*k}, *pvec{data + v0 + vk*k};
		
		tag = *reinterpret_cast<int*>(ptag);
		for (int j=0; j<n; ++j) {
			vec[j] = *reinterpret_cast<float*>(pvec + vj*j);
		}
	}

	//------------------------------------------------------------------//
	void writept
	(const int& k, const int& n, const int& tag, const float vec[]) {
		char *ptag{data + tk*k}, *pvec{data + v0 + vk*k};
		
		*reinterpret_cast<int*>(ptag) = tag;
		for (int j=0; j<n; ++j) {
			*reinterpret_cast<float*>(pvec + vj*j) = vec[j];
		}
	}
};

Исходная версия thunar, :

Вот что я хотел:

struct pool_t {

private:
	char   *data;
	size_t  tk, v0, vk, vj; 

public:
	enum ord {row, col};

	//------------------------------------------------------------------//
	pool_t (char* p, int nk, int nj, ord arg) : data(p) {
		switch (arg) {
			case ord::row:
			tk = sizeof(int) + sizeof(float)*nj;
			v0 = sizeof(int);
			vk = sizeof(int) + sizeof(float)*nj;
			vj = sizeof(float);
			return;
			case ord::col:
			tk = sizeof(int);
			v0 = sizeof(int)*nk;
			vk = sizeof(float);
			vj = sizeof(float)*nk;
			return;
		}
	}

	//------------------------------------------------------------------//
	void readpt
	(const int& k, const int& n, int& tag, float vec[]) {
		char *pt{data + tk*k}, *vt{data + v0 + vk*k};
		
		tag = *reinterpret_cast<int*>(pt);
		for (int j=0; j<n; ++j) {
			vec[j] = *reinterpret_cast<float*>(vt + vj*j);
		}
	}

	//------------------------------------------------------------------//
	void writept
	(const int& k, const int& n, const int& tag, const float vec[]) {
		char *pt{data + tk*k}, *vt{data + v0 + vk*k};
		
		*reinterpret_cast<int*>(pt) = tag;
		for (int j=0; j<n; ++j) {
			*reinterpret_cast<float*>(vt + vj*j) = vec[j];
		}
	}
};