🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #308690

Szukanie w unordered_map potrzebuje operatora == a on jest

#308690
From: Borneq
Date: Mon, 13 Jun 2016 10:08
120 lines
3140 bytes
Jest:
using namespace std;

struct inputTx_s
{
	uint8_t hash[32];
	uint32_t index;

	int cmp(const inputTx_s& rhs)
	{
		int res = 0;
		bool isNonZero = false;
		for (int i = 0; i < 32; i++)
			if (hash[i] < rhs.hash[i])
			{
				res = -1;
				break;
			}
			else if (hash[i] > rhs.hash[i])
			{
				res = 1;
				break;
			}
			else if (hash[i] != 0)
				isNonZero = true;
		if (isNonZero)
		{
			if (index < rhs.index)
				res = -1;
			else if (index > rhs.index)
				res = 1;
		}
		return res;
	}

	bool operator < (const inputTx_s& rhs)
	{
		return cmp(rhs)<0;
	}

	bool operator <= (const inputTx_s& rhs)
	{
		return cmp(rhs) <= 0;
	}

	bool operator == (const inputTx_s& rhs)
	{
		return cmp(rhs) == 0;
	}

	bool operator != (const inputTx_s& rhs)
	{
		return cmp(rhs) != 0;
	}

	bool operator >= (const inputTx_s& rhs)
	{
		return cmp(rhs) >= 0;
	}

	bool operator > (const inputTx_s& rhs)
	{
		return cmp(rhs) > 0;
	}
};

struct outputTx_s
{
	char address[36];
	uint64_t amount;
	outputTx_s() {};
	outputTx_s(string addrStr)
	{
		strncpyc(address, addrStr.c_str(), sizeof(address));
	}
};

struct hash_inputTx {
	//http://isthe.com/chongo/tech/comp/fnv/
	static size_t FNV_1(const uint8_t *bytes, size_t count)
	{
		size_t hash, FNV_prime;
		if (sizeof(size_t) > 4)
		{
			hash = 14695981039346656037;
			FNV_prime = 1099511628211;
		}
		else
		{
			hash = 2166136261;
			FNV_prime = 16777619;
		}
		if (count > 0)
			for (size_t i = 0; i < count; i++)
			{
				hash *= FNV_prime;
				hash ^= bytes[i];
			}
		return hash;
	}

	size_t operator()(const inputTx_s &tx) const {
		return FNV_1(tx.hash, sizeof(tx.hash)) ^ FNV_1((uint8_t*)&tx.index, 
sizeof(tx.index));
	}
};
=================================
Mam unordered_map<inputTx_s, outputTx_s, hash_inputTx> map;
Błąd gdy unordered_map<inputTx_s, outputTx_s, 
hash_inputTx>::const_iterator iter = map.find(input);

Severity Code
Description  Project File
Line Suppression State
Error C2678
binary '==': no operator found which takes a left-hand operand of type 
'const inputTx_s' (or there is no acceptable conversion)
BlockNew C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\xstddef
225
Technical Details
Message-ID: <njm0n9$can$1@node2.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: Borneq <borneq@antyspam.hidden.pl>
Newsgroups: pl.comp.lang.c
Subject: Szukanie w unordered_map potrzebuje operatora == a on jest
Date: Mon, 13 Jun 2016 12:08:41 +0200
Organization: ATMAN - ATM S.A.
Lines: 120
Message-ID: <njm0n9$can$1@node2.news.atman.pl>
NNTP-Posting-Host: 91.239.205.105
Mime-Version: 1.0
X-Trace: node2.news.atman.pl 1465812521 12631 91.239.205.105 (13 Jun 2016 10:08:41 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Mon, 13 Jun 2016 10:08:41 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1
X-Mozilla-News-Host: news://news.atman.pl:119
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit