diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-04 00:00:14 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-02-04 00:00:14 +0000 |
commit | 70327112cb2679dcf0e4879d71fe745c33a42bb7 (patch) | |
tree | bcd43231e89be2a71eab3810a29463702378d91b /vespalib | |
parent | 730d3e0d462fcc69aaa47c30f1ed868471ce10ad (diff) |
Drop boost crc, random and tokenizer
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/bits/bits_test.cpp | 34 | ||||
-rw-r--r-- | vespalib/src/tests/crc/crc_test.cpp | 47 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/crc.h | 1 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/rand48.h | 11 |
4 files changed, 37 insertions, 56 deletions
diff --git a/vespalib/src/tests/bits/bits_test.cpp b/vespalib/src/tests/bits/bits_test.cpp index 47d691c739d..7d4de014860 100644 --- a/vespalib/src/tests/bits/bits_test.cpp +++ b/vespalib/src/tests/bits/bits_test.cpp @@ -2,14 +2,6 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/bits.h> -#include <boost/crc.hpp> -#include <boost/version.hpp> - -#if BOOST_VERSION < 106900 - #define REFLECT reflect -#else - #define REFLECT reflect_q -#endif using namespace vespalib; @@ -18,7 +10,7 @@ class Test : public TestApp public: int Main() override; template <typename T> - void testFixed(const T * v, size_t sz); + void testFixed(const T * v, size_t sz, const T * exp); void testBuffer(); }; @@ -26,26 +18,30 @@ int Test::Main() { TEST_INIT("bits_test"); - uint8_t u8[5] = { 0, 1, 127, 135, 255 }; - testFixed(u8, sizeof(u8)/sizeof(u8[0])); - uint16_t u16[5] = { 0, 1, 127, 135, 255 }; - testFixed(u16, sizeof(u16)/sizeof(u16[0])); - uint32_t u32[5] = { 0, 1, 127, 135, 255 }; - testFixed(u32, sizeof(u32)/sizeof(u32[0])); - uint64_t u64[5] = { 0, 1, 127, 135, 255 }; - testFixed(u64, sizeof(u64)/sizeof(u64[0])); + uint8_t u8[5] = { 0, 0x1, 0x7f, 0x87, 0xff }; + uint8_t exp8[5] = { 0, 0x80, 0xfe, 0xe1, 0xff }; + testFixed(u8, sizeof(u8)/sizeof(u8[0]), exp8); + uint16_t u16[5] = { 0, 0x1, 0x7f, 0x87, 0xff }; + uint16_t exp16[5] = { 0, 0x8000, 0xfe00, 0xe100, 0xff00 }; + testFixed(u16, sizeof(u16)/sizeof(u16[0]), exp16); + uint32_t u32[5] = { 0, 0x1, 0x7f, 0x87, 0xff }; + uint32_t exp32[5] = { 0, 0x80000000, 0xfe000000, 0xe1000000, 0xff000000 }; + testFixed(u32, sizeof(u32)/sizeof(u32[0]), exp32); + uint64_t u64[5] = { 0, 0x1, 0x7f, 0x87, 0xff }; + uint64_t exp64[5] = { 0, 0x8000000000000000, 0xfe00000000000000, 0xe100000000000000, 0xff00000000000000 }; + testFixed(u64, sizeof(u64)/sizeof(u64[0]), exp64); testBuffer(); TEST_DONE(); } template <typename T> -void Test::testFixed(const T * v, size_t sz) +void Test::testFixed(const T * v, size_t sz, const T * exp) { EXPECT_EQUAL(0u, Bits::reverse(static_cast<T>(0))); EXPECT_EQUAL(1ul << (sizeof(T)*8 - 1), Bits::reverse(static_cast<T>(1))); EXPECT_EQUAL(static_cast<T>(-1), Bits::reverse(static_cast<T>(-1))); for (size_t i(0); i < sz; i++) { - EXPECT_EQUAL(Bits::reverse(v[i]), boost::detail::reflector<sizeof(T)*8>::REFLECT(v[i])); + EXPECT_EQUAL(Bits::reverse(v[i]), exp[i]); EXPECT_EQUAL(Bits::reverse(Bits::reverse(v[i])), v[i]); } } diff --git a/vespalib/src/tests/crc/crc_test.cpp b/vespalib/src/tests/crc/crc_test.cpp index 8afeed487ee..28e904b5056 100644 --- a/vespalib/src/tests/crc/crc_test.cpp +++ b/vespalib/src/tests/crc/crc_test.cpp @@ -2,7 +2,6 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/crc.h> -#include <boost/crc.hpp> #include <vector> using namespace vespalib; @@ -12,7 +11,7 @@ class Test : public TestApp public: int Main() override; void testCorrectNess(); - void testBenchmark(bool our, size_t bufSz, size_t numRep); + void testBenchmark(size_t bufSz, size_t numRep); }; int @@ -20,57 +19,43 @@ Test::Main() { TEST_INIT("crc_test"); testCorrectNess(); - if (_argc >= 2) { - testBenchmark(false, 1024, 1000*1000); - } else { - testBenchmark(true, 1024, 1000*1000); - } + testBenchmark(1024, 1000*1000); TEST_DONE(); } -void Test::testCorrectNess() +void +Test::testCorrectNess() { const char *a[7] = { "", "a", "ab", "abc", "abcd", "abcde", "doc:crawler:http://www.ntnu.no/" }; + uint32_t expected[7] = {0, 0xe8b7be43, 0x9e83486d, 0x352441c2, 0xed82cd11, 0x8587d865, 0x86287fc5}; for (size_t i(0); i < sizeof(a)/sizeof(a[0]); i++) { uint32_t vespaCrc32 = crc_32_type::crc(a[i], strlen(a[i])); - boost::crc_32_type calculator; - calculator.process_bytes(a[i], strlen(a[i])); - EXPECT_EQUAL(vespaCrc32, calculator.checksum()); + EXPECT_EQUAL(vespaCrc32, expected[i]); vespalib::crc_32_type calculator2; calculator2.process_bytes(a[i], strlen(a[i])); EXPECT_EQUAL(vespaCrc32, calculator2.checksum()); - EXPECT_EQUAL(calculator.checksum(), calculator2.checksum()); } - vespalib::crc_32_type calculator2; - boost::crc_32_type calculator; + vespalib::crc_32_type calculator; + uint32_t accum_expected[7] = {0, 0xe8b7be43, 0x690e2297, 0x8d7284f9, 0x7ed0c389, 0x61bc2a26, 0x1816e339}; for (size_t i(0); i < sizeof(a)/sizeof(a[0]); i++) { calculator.process_bytes(a[i], strlen(a[i])); - calculator2.process_bytes(a[i], strlen(a[i])); - EXPECT_EQUAL(calculator.checksum(), calculator2.checksum()); + EXPECT_EQUAL(calculator.checksum(), accum_expected[i]); } - EXPECT_EQUAL(calculator.checksum(), calculator2.checksum()); } -void Test::testBenchmark(bool our, size_t bufSz, size_t numRep) +void +Test::testBenchmark(size_t bufSz, size_t numRep) { std::vector<char> a(numRep+bufSz); for(size_t i(0), m(a.size()); i < m; i++) { a[i] = i&0xff; } uint32_t sum(0); - if (our) { - for (size_t i(0); i < (numRep); i++) { - //sum ^= crc_32_type::crc(&a[i], bufSz); - vespalib::crc_32_type calculator; - calculator.process_bytes(&a[i], bufSz); - sum ^=calculator.checksum(); - } - } else { - for (size_t i(0); i < (numRep); i++) { - boost::crc_32_type calculator; - calculator.process_bytes(&a[i], bufSz); - sum ^=calculator.checksum(); - } + for (size_t i(0); i < (numRep); i++) { + //sum ^= crc_32_type::crc(&a[i], bufSz); + vespalib::crc_32_type calculator; + calculator.process_bytes(&a[i], bufSz); + sum ^=calculator.checksum(); } printf("sum = %x\n", sum); } diff --git a/vespalib/src/vespa/vespalib/util/crc.h b/vespalib/src/vespa/vespalib/util/crc.h index f5acafeff36..3e65946bd8c 100644 --- a/vespalib/src/vespa/vespalib/util/crc.h +++ b/vespalib/src/vespa/vespalib/util/crc.h @@ -14,7 +14,6 @@ class crc_32_type { public: crc_32_type() : _c(uint32_t(-1)) { } - void process_block(const void *start, const void *end) { process_bytes(start, (const uint8_t *)end-(const uint8_t *)start); } void process_bytes(const void *start, size_t sz); uint32_t checksum() const { return _c ^ uint32_t(-1); } static uint32_t crc(const void * v, size_t sz); diff --git a/vespalib/src/vespa/vespalib/util/rand48.h b/vespalib/src/vespa/vespalib/util/rand48.h index 05290585f6d..374096404d5 100644 --- a/vespalib/src/vespa/vespalib/util/rand48.h +++ b/vespalib/src/vespa/vespalib/util/rand48.h @@ -15,17 +15,18 @@ class Rand48 private: uint64_t _state; public: - void - srand48(long seed) - { + void srand48(long seed) { _state = ((static_cast<uint64_t>(seed & 0xffffffffu)) << 16) + 0x330e; } Rand48() + : Rand48(0x1234abcd) + { } + explicit Rand48(long seed) : _state(0) { - srand48(0x1234abcd); - }; + srand48(seed); + } void iterate() { _state = (UINT64_C(0x5DEECE66D) * _state + 0xb) & UINT64_C(0xFFFFFFFFFFFF); |