26 #ifndef DCCLConstants20091211H
27 #define DCCLConstants20091211H
33 #include <type_traits>
35 #include <google/protobuf/descriptor.h>
36 #include <google/protobuf/message.h>
42 inline unsigned floor_bits2bytes(
unsigned bits) {
return bits >> 3; }
45 inline unsigned ceil_bits2bytes(
unsigned bits)
51 return (bits & BYTE_MASK) ? floor_bits2bytes(bits) + 1 : floor_bits2bytes(bits);
56 typedef google::protobuf::uint32
uint32;
58 using int32 = google::protobuf::int32;
60 using uint64 = google::protobuf::uint64;
62 using int64 = google::protobuf::int64;
64 const unsigned BITS_IN_BYTE = 8;
68 return (out <<
"[[" << msg.GetDescriptor()->name() <<
"]] " << msg.DebugString());
71 template <
typename Float> Float round(Float d) {
return std::floor(d + 0.5); }
77 template <
typename Float>
78 typename std::enable_if<std::is_floating_point<Float>::value, Float>::type round(Float value,
81 Float scaling = std::pow(10.0, precision);
82 return round(value * scaling) / scaling;
89 template <
typename Float>
90 typename std::enable_if<std::is_floating_point<Float>::value, Float>::type quantize(Float value,
94 return round(value / interval) * interval;
97 double interval_inv = 1.0 / interval;
98 return round(value * interval_inv) / interval_inv;
103 template <
typename Int> Int abs(Int i) {
return (i < 0) ? -i : i; }
109 template <
typename Int>
110 typename std::enable_if<std::is_integral<Int>::value, Int>::type round(Int value,
int precision)
119 Int scaling = (Int)std::pow(10.0, -precision);
120 Int remainder = value % scaling;
123 if (remainder >= scaling / 2)
134 template <
typename Int>
135 typename std::enable_if<std::is_integral<Int>::value, Int>::type quantize(Int value,
138 if ((interval -
static_cast<uint64_t
>(interval)) >= std::numeric_limits<double>::epsilon())
144 Int remainder = value %
static_cast<Int
>(interval);
146 if (remainder >= interval / 2)
152 template <
class T>
inline void hash_combine(std::size_t& seed,
const T& v)
155 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);