Remove unused Beast code

This commit is contained in:
Nik Bougalis
2020-12-19 02:32:37 -08:00
parent 74d96ff4bd
commit c76a124d14
5 changed files with 25 additions and 378 deletions

View File

@@ -273,7 +273,6 @@ install (
install (
FILES
src/ripple/beast/hash/hash_append.h
src/ripple/beast/hash/meta.h
src/ripple/beast/hash/uhash.h
src/ripple/beast/hash/xxhasher.h
DESTINATION include/ripple/beast/hash)

View File

@@ -21,7 +21,6 @@
#ifndef BEAST_HASH_HASH_APPEND_H_INCLUDED
#define BEAST_HASH_HASH_APPEND_H_INCLUDED
#include <ripple/beast/hash/meta.h>
#include <boost/container/flat_set.hpp>
#include <boost/endian/conversion.hpp>
#include <array>
@@ -140,8 +139,8 @@ template <class... T>
struct is_uniquely_represented<std::tuple<T...>>
: public std::integral_constant<
bool,
static_and<is_uniquely_represented<T>::value...>::value &&
static_sum<sizeof(T)...>::value == sizeof(std::tuple<T...>)>
std::conjunction_v<is_uniquely_represented<T>...> &&
sizeof(std::tuple<T...>) == (sizeof(T) + ...)>
{
explicit is_uniquely_represented() = default;
};

View File

@@ -1,143 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2014, Howard Hinnant <howard.hinnant@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_HASH_META_H_INCLUDED
#define BEAST_HASH_META_H_INCLUDED
#include <type_traits>
namespace beast {
template <bool...>
struct static_and;
template <bool b0, bool... bN>
struct static_and<b0, bN...>
: public std::integral_constant<bool, b0 && static_and<bN...>::value>
{
explicit static_and() = default;
};
template <>
struct static_and<> : public std::true_type
{
explicit static_and() = default;
};
#ifndef __INTELLISENSE__
static_assert(static_and<true, true, true>::value, "");
static_assert(!static_and<true, false, true>::value, "");
#endif
template <std::size_t...>
struct static_sum;
template <std::size_t s0, std::size_t... sN>
struct static_sum<s0, sN...>
: public std::integral_constant<std::size_t, s0 + static_sum<sN...>::value>
{
explicit static_sum() = default;
};
template <>
struct static_sum<> : public std::integral_constant<std::size_t, 0>
{
explicit static_sum() = default;
};
#ifndef __INTELLISENSE__
static_assert(static_sum<5, 2, 17, 0>::value == 24, "");
#endif
template <class T, class U>
struct enable_if_lvalue : public std::enable_if<
std::is_same<std::decay_t<T>, U>::value &&
std::is_lvalue_reference<T>::value>
{
explicit enable_if_lvalue() = default;
};
/** Ensure const reference function parameters are valid lvalues.
Some functions, especially class constructors, accept const references and
store them for later use. If any of those parameters are rvalue objects,
the object will be freed as soon as the function returns. This could
potentially lead to a variety of "use after free" errors.
If the function is rewritten as a template using this type and the
parameters references as rvalue references (eg. TX&&), a compiler
error will be generated if an rvalue is provided in the caller.
@code
// Example:
struct X
{
};
struct Y
{
};
struct Unsafe
{
Unsafe (X const& x, Y const& y)
: x_ (x)
, y_ (y)
{
}
X const& x_;
Y const& y_;
};
struct Safe
{
template <class TX, class TY,
class = beast::enable_if_lvalue_t<TX, X>,
class = beast::enable_if_lvalue_t < TY, Y >>
Safe (TX&& x, TY&& y)
: x_ (x)
, y_ (y)
{
}
X const& x_;
Y const& y_;
};
struct demo
{
void
createObjects ()
{
X x {};
Y const y {};
Unsafe u1 (x, y); // ok
Unsafe u2 (X (), y); // compiles, but u2.x_ becomes invalid at
the end of the line. Safe s1 (x, y); // ok
// Safe s2 (X (), y); // compile-time error
}
};
@endcode
*/
template <class T, class U>
using enable_if_lvalue_t = typename enable_if_lvalue<T, U>::type;
} // namespace beast
#endif // BEAST_UTILITY_META_H_INCLUDED

View File

@@ -1,201 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2014, Howard Hinnant <howard.hinnant@gmail.com>,
Vinnie Falco <vinnie.falco@gmail.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_HASH_HASH_METRICS_H_INCLUDED
#define BEAST_HASH_HASH_METRICS_H_INCLUDED
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <set>
#include <utility>
#include <vector>
namespace beast {
namespace hash_metrics {
// Metrics for measuring the quality of container hash functions
/** Returns the fraction of duplicate items in the sequence. */
template <class FwdIter>
float
collision_factor(FwdIter first, FwdIter last)
{
std::set<typename FwdIter::value_type> s(first, last);
return 1 - static_cast<float>(s.size()) / std::distance(first, last);
}
//------------------------------------------------------------------------------
/** Returns the deviation of the sequence from the ideal distribution. */
template <class FwdIter>
float
distribution_factor(FwdIter first, FwdIter last)
{
using value_type = typename FwdIter::value_type;
static_assert(std::is_unsigned<value_type>::value, "");
const unsigned nbits = CHAR_BIT * sizeof(std::size_t);
const unsigned rows = nbits / 4;
unsigned counts[rows][16] = {};
std::for_each(first, last, [&](typename FwdIter::value_type h) {
std::size_t mask = 0xF;
for (unsigned i = 0; i < rows; ++i, mask <<= 4)
counts[i][(h & mask) >> 4 * i] += 1;
});
float mean_rows[rows] = {0};
float mean_cols[16] = {0};
for (unsigned i = 0; i < rows; ++i)
{
for (unsigned j = 0; j < 16; ++j)
{
mean_rows[i] += counts[i][j];
mean_cols[j] += counts[i][j];
}
}
for (unsigned i = 0; i < rows; ++i)
mean_rows[i] /= 16;
for (unsigned j = 0; j < 16; ++j)
mean_cols[j] /= rows;
std::pair<float, float> dev[rows][16];
for (unsigned i = 0; i < rows; ++i)
{
for (unsigned j = 0; j < 16; ++j)
{
dev[i][j].first =
std::abs(counts[i][j] - mean_rows[i]) / mean_rows[i];
dev[i][j].second =
std::abs(counts[i][j] - mean_cols[j]) / mean_cols[j];
}
}
float max_err = 0;
for (unsigned i = 0; i < rows; ++i)
{
for (unsigned j = 0; j < 16; ++j)
{
if (max_err < dev[i][j].first)
max_err = dev[i][j].first;
if (max_err < dev[i][j].second)
max_err = dev[i][j].second;
}
}
return max_err;
}
//------------------------------------------------------------------------------
namespace detail {
template <class T>
inline T
sqr(T t)
{
return t * t;
}
double
score(int const* bins, std::size_t const bincount, double const k)
{
double const n = bincount;
// compute rms^2 value
double rms_sq = 0;
for (std::size_t i = 0; i < bincount; ++i)
rms_sq += sqr(bins[i]);
;
rms_sq /= n;
// compute fill factor
double const f = (sqr(k) - 1) / (n * rms_sq - k);
// rescale to (0,1) with 0 = good, 1 = bad
return 1 - (f / n);
}
template <class T>
std::uint32_t
window(T* blob, int start, int count)
{
std::size_t const len = sizeof(T);
static_assert((len & 3) == 0, "");
if (count == 0)
return 0;
int const nbits = len * CHAR_BIT;
start %= nbits;
int ndwords = len / 4;
std::uint32_t const* k =
static_cast<std::uint32_t const*>(static_cast<void const*>(blob));
int c = start & (32 - 1);
int d = start / 32;
if (c == 0)
return (k[d] & ((1 << count) - 1));
int ia = (d + 1) % ndwords;
int ib = (d + 0) % ndwords;
std::uint32_t a = k[ia];
std::uint32_t b = k[ib];
std::uint32_t t = (a << (32 - c)) | (b >> c);
t &= ((1 << count) - 1);
return t;
}
} // namespace detail
/** Calculated a windowed metric using bins.
TODO Need reference (SMHasher?)
*/
template <class FwdIter>
double
windowed_score(FwdIter first, FwdIter last)
{
auto const size(std::distance(first, last));
int maxwidth = 20;
// We need at least 5 keys per bin to reliably test distribution biases
// down to 1%, so don't bother to test sparser distributions than that
while (static_cast<double>(size) / (1ull << maxwidth) < 5.0)
maxwidth--;
double worst = 0;
std::vector<int> bins(1ull << maxwidth);
int const hashbits = sizeof(std::size_t) * CHAR_BIT;
for (int start = 0; start < hashbits; ++start)
{
int width = maxwidth;
bins.assign(1ull << width, 0);
for (auto iter(first); iter != last; ++iter)
++bins[detail::window(&*iter, start, width)];
// Test the distribution, then fold the bins in half,
// repeat until we're down to 256 bins
while (bins.size() >= 256)
{
double score(detail::score(bins.data(), bins.size(), size));
worst = std::max(score, worst);
if (--width < 8)
break;
for (std::size_t i = 0, j = bins.size() / 2; j < bins.size();
++i, ++j)
bins[i] += bins[j];
bins.resize(bins.size() / 2);
}
}
return worst;
}
} // namespace hash_metrics
} // namespace beast
#endif

View File

@@ -20,52 +20,45 @@
#ifndef BEAST_TYPE_NAME_H_INCLUDED
#define BEAST_TYPE_NAME_H_INCLUDED
#include <iostream>
#include <cstdlib>
#include <string>
#include <type_traits>
#include <typeinfo>
#ifndef _MSC_VER
#include <cxxabi.h>
#endif
#include <cstdlib>
#include <memory>
#include <string>
#include <vector>
namespace beast {
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
template <typename T>
std::string
type_name()
{
using TR = typename std::remove_reference<T>::type;
std::unique_ptr<char, void (*)(void*)> own(
#ifndef _MSC_VER
abi::__cxa_demangle(typeid(TR).name(), nullptr, nullptr, nullptr),
#else
nullptr,
#endif
std::free);
std::string r = own != nullptr ? own.get() : typeid(TR).name();
if (std::is_const<TR>::value)
r += " const";
if (std::is_volatile<TR>::value)
r += " volatile";
if (std::is_lvalue_reference<T>::value)
r += "&";
else if (std::is_rvalue_reference<T>::value)
r += "&&";
return r;
}
#ifdef _MSC_VER
#pragma warning(pop)
std::string name = typeid(TR).name();
#ifndef _MSC_VER
if (auto s = abi::__cxa_demangle(name.c_str(), nullptr, nullptr, nullptr))
{
name = s;
std::free(s);
}
#endif
if (std::is_const<TR>::value)
name += " const";
if (std::is_volatile<TR>::value)
name += " volatile";
if (std::is_lvalue_reference<T>::value)
name += "&";
else if (std::is_rvalue_reference<T>::value)
name += "&&";
return name;
}
} // namespace beast
#endif