Browse Source

Remove now-unused methods from arith_uint256 and base_uint

- Methods that access the guts of arith_uint256 are removed,
as these are incompatible between endians. Use uint256 instead

- Serialization is no longer needed as arith_uint256's are never
read or written

- GetHash is never used on arith_uint256
0.13
Wladimir J. van der Laan 10 years ago
parent
commit
30007fda76
  1. 62
      src/arith_uint256.cpp
  2. 56
      src/arith_uint256.h
  3. 31
      src/test/arith_uint256_tests.cpp

62
src/arith_uint256.cpp

@ -278,68 +278,6 @@ uint32_t arith_uint256::GetCompact(bool fNegative) const
return nCompact; return nCompact;
} }
static void inline HashMix(uint32_t& a, uint32_t& b, uint32_t& c)
{
// Taken from lookup3, by Bob Jenkins.
a -= c;
a ^= ((c << 4) | (c >> 28));
c += b;
b -= a;
b ^= ((a << 6) | (a >> 26));
a += c;
c -= b;
c ^= ((b << 8) | (b >> 24));
b += a;
a -= c;
a ^= ((c << 16) | (c >> 16));
c += b;
b -= a;
b ^= ((a << 19) | (a >> 13));
a += c;
c -= b;
c ^= ((b << 4) | (b >> 28));
b += a;
}
static void inline HashFinal(uint32_t& a, uint32_t& b, uint32_t& c)
{
// Taken from lookup3, by Bob Jenkins.
c ^= b;
c -= ((b << 14) | (b >> 18));
a ^= c;
a -= ((c << 11) | (c >> 21));
b ^= a;
b -= ((a << 25) | (a >> 7));
c ^= b;
c -= ((b << 16) | (b >> 16));
a ^= c;
a -= ((c << 4) | (c >> 28));
b ^= a;
b -= ((a << 14) | (a >> 18));
c ^= b;
c -= ((b << 24) | (b >> 8));
}
uint64_t arith_uint256::GetHash(const arith_uint256& salt) const
{
uint32_t a, b, c;
a = b = c = 0xdeadbeef + (WIDTH << 2);
a += pn[0] ^ salt.pn[0];
b += pn[1] ^ salt.pn[1];
c += pn[2] ^ salt.pn[2];
HashMix(a, b, c);
a += pn[3] ^ salt.pn[3];
b += pn[4] ^ salt.pn[4];
c += pn[5] ^ salt.pn[5];
HashMix(a, b, c);
a += pn[6] ^ salt.pn[6];
b += pn[7] ^ salt.pn[7];
HashFinal(a, b, c);
return ((((uint64_t)b) << 32) | c);
}
uint256 ArithToUint256(const arith_uint256 &a) uint256 ArithToUint256(const arith_uint256 &a)
{ {
uint256 b; uint256 b;

56
src/arith_uint256.h

@ -232,26 +232,6 @@ public:
void SetHex(const std::string& str); void SetHex(const std::string& str);
std::string ToString() const; std::string ToString() const;
unsigned char* begin()
{
return (unsigned char*)&pn[0];
}
unsigned char* end()
{
return (unsigned char*)&pn[WIDTH];
}
const unsigned char* begin() const
{
return (unsigned char*)&pn[0];
}
const unsigned char* end() const
{
return (unsigned char*)&pn[WIDTH];
}
unsigned int size() const unsigned int size() const
{ {
return sizeof(pn); return sizeof(pn);
@ -268,40 +248,6 @@ public:
assert(WIDTH >= 2); assert(WIDTH >= 2);
return pn[0] | (uint64_t)pn[1] << 32; return pn[0] | (uint64_t)pn[1] << 32;
} }
unsigned int GetSerializeSize(int nType, int nVersion) const
{
return sizeof(pn);
}
template<typename Stream>
void Serialize(Stream& s, int nType, int nVersion) const
{
s.write((char*)pn, sizeof(pn));
}
template<typename Stream>
void Unserialize(Stream& s, int nType, int nVersion)
{
s.read((char*)pn, sizeof(pn));
}
// Temporary for migration to blob160/256
uint64_t GetCheapHash() const
{
return GetLow64();
}
void SetNull()
{
memset(pn, 0, sizeof(pn));
}
bool IsNull() const
{
for (int i = 0; i < WIDTH; i++)
if (pn[i] != 0)
return false;
return true;
}
}; };
/** 256-bit unsigned big integer. */ /** 256-bit unsigned big integer. */
@ -336,8 +282,6 @@ public:
arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL); arith_uint256& SetCompact(uint32_t nCompact, bool *pfNegative = NULL, bool *pfOverflow = NULL);
uint32_t GetCompact(bool fNegative = false) const; uint32_t GetCompact(bool fNegative = false) const;
uint64_t GetHash(const arith_uint256& salt) const;
friend uint256 ArithToUint256(const arith_uint256 &); friend uint256 ArithToUint256(const arith_uint256 &);
friend arith_uint256 UintToArith256(const uint256 &); friend arith_uint256 UintToArith256(const uint256 &);
}; };

31
src/test/arith_uint256_tests.cpp

@ -370,7 +370,7 @@ bool almostEqual(double d1, double d2)
return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits<double>::epsilon(); return fabs(d1-d2) <= 4*fabs(d1)*std::numeric_limits<double>::epsilon();
} }
BOOST_AUTO_TEST_CASE( methods ) // GetHex SetHex begin() end() size() GetLow64 GetSerializeSize, Serialize, Unserialize BOOST_AUTO_TEST_CASE( methods ) // GetHex SetHex size() GetLow64 GetSerializeSize, Serialize, Unserialize
{ {
BOOST_CHECK(R1L.GetHex() == R1L.ToString()); BOOST_CHECK(R1L.GetHex() == R1L.ToString());
BOOST_CHECK(R2L.GetHex() == R2L.ToString()); BOOST_CHECK(R2L.GetHex() == R2L.ToString());
@ -383,42 +383,13 @@ BOOST_AUTO_TEST_CASE( methods ) // GetHex SetHex begin() end() size() GetLow64 G
TmpL.SetHex(HalfL.ToString()); BOOST_CHECK(TmpL == HalfL); TmpL.SetHex(HalfL.ToString()); BOOST_CHECK(TmpL == HalfL);
TmpL.SetHex(R1L.ToString()); TmpL.SetHex(R1L.ToString());
BOOST_CHECK(memcmp(R1L.begin(), R1Array, 32)==0);
BOOST_CHECK(memcmp(TmpL.begin(), R1Array, 32)==0);
BOOST_CHECK(memcmp(R2L.begin(), R2Array, 32)==0);
BOOST_CHECK(memcmp(ZeroL.begin(), ZeroArray, 32)==0);
BOOST_CHECK(memcmp(OneL.begin(), OneArray, 32)==0);
BOOST_CHECK(R1L.size() == 32); BOOST_CHECK(R1L.size() == 32);
BOOST_CHECK(R2L.size() == 32); BOOST_CHECK(R2L.size() == 32);
BOOST_CHECK(ZeroL.size() == 32); BOOST_CHECK(ZeroL.size() == 32);
BOOST_CHECK(MaxL.size() == 32); BOOST_CHECK(MaxL.size() == 32);
BOOST_CHECK(R1L.begin() + 32 == R1L.end());
BOOST_CHECK(R2L.begin() + 32 == R2L.end());
BOOST_CHECK(OneL.begin() + 32 == OneL.end());
BOOST_CHECK(MaxL.begin() + 32 == MaxL.end());
BOOST_CHECK(TmpL.begin() + 32 == TmpL.end());
BOOST_CHECK(R1L.GetLow64() == R1LLow64); BOOST_CHECK(R1L.GetLow64() == R1LLow64);
BOOST_CHECK(HalfL.GetLow64() ==0x0000000000000000ULL); BOOST_CHECK(HalfL.GetLow64() ==0x0000000000000000ULL);
BOOST_CHECK(OneL.GetLow64() ==0x0000000000000001ULL); BOOST_CHECK(OneL.GetLow64() ==0x0000000000000001ULL);
BOOST_CHECK(R1L.GetSerializeSize(0,PROTOCOL_VERSION) == 32);
BOOST_CHECK(ZeroL.GetSerializeSize(0,PROTOCOL_VERSION) == 32);
std::stringstream ss;
R1L.Serialize(ss,0,PROTOCOL_VERSION);
BOOST_CHECK(ss.str() == std::string(R1Array,R1Array+32));
TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
BOOST_CHECK(R1L == TmpL);
ss.str("");
ZeroL.Serialize(ss,0,PROTOCOL_VERSION);
BOOST_CHECK(ss.str() == std::string(ZeroArray,ZeroArray+32));
TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
BOOST_CHECK(ZeroL == TmpL);
ss.str("");
MaxL.Serialize(ss,0,PROTOCOL_VERSION);
BOOST_CHECK(ss.str() == std::string(MaxArray,MaxArray+32));
TmpL.Unserialize(ss,0,PROTOCOL_VERSION);
BOOST_CHECK(MaxL == TmpL);
ss.str("");
for (unsigned int i = 0; i < 255; ++i) for (unsigned int i = 0; i < 255; ++i)
{ {

Loading…
Cancel
Save