2015-07-15 12:23:00 +00:00
|
|
|
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
|
|
|
|
//
|
|
|
|
// This file is part of Bytecoin.
|
|
|
|
//
|
|
|
|
// Bytecoin is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Bytecoin is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
#define CRYPTO_MAKE_COMPARABLE(type) \
|
|
|
|
namespace crypto { \
|
|
|
|
inline bool operator==(const type &_v1, const type &_v2) { \
|
|
|
|
return std::memcmp(&_v1, &_v2, sizeof(type)) == 0; \
|
|
|
|
} \
|
|
|
|
inline bool operator!=(const type &_v1, const type &_v2) { \
|
|
|
|
return std::memcmp(&_v1, &_v2, sizeof(type)) != 0; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CRYPTO_MAKE_HASHABLE(type) \
|
|
|
|
CRYPTO_MAKE_COMPARABLE(type) \
|
|
|
|
namespace crypto { \
|
|
|
|
static_assert(sizeof(std::size_t) <= sizeof(type), "Size of " #type " must be at least that of size_t"); \
|
|
|
|
inline std::size_t hash_value(const type &_v) { \
|
|
|
|
return reinterpret_cast<const std::size_t &>(_v); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
namespace std { \
|
|
|
|
template<> \
|
|
|
|
struct hash<crypto::type> { \
|
|
|
|
std::size_t operator()(const crypto::type &_v) const { \
|
|
|
|
return reinterpret_cast<const std::size_t &>(_v); \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
}
|