tudocomp
– The TU Dortmund Compression Framework
def.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstddef>
4 #include <limits>
5 #include <type_traits>
6 
7 #include <tudocomp/ds/uint_t.hpp>
8 
9 // assertions
10 #if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__)
11  #define tdc_likely(x) __builtin_expect((x) != 0, 1)
14  #define tdc_unlikely(x) __builtin_expect((x) != 0, 0)
17 #else
18  #define tdc_likely(x) x
21  #define tdc_unlikely(x) x
24 #endif
25 
26 // code compiled only in debug build (set build type to Debug)
27 #ifdef DEBUG
28  #define IF_DEBUG(x) x
30 #else
31  #define IF_DEBUG(x)
33 
34  #if defined(GOOGLE_STRIP_LOG)
35  #undef GOOGLE_STRIP_LOG
36  #endif
37 
38  #define GOOGLE_STRIP_LOG 1 // no google logging
39 #endif
40 
41 // code compiled only in paranoid debug build (pass -DPARANOID=1 to CMake)
42 #if defined(DEBUG) && defined(PARANOID)
43  #define IF_PARANOID(x) x
46 #else
47  #define IF_PARANOID(x)
50 #endif
51 
52 // code compiled only if statistics tracking is enabled (default yes)
53 // (pass -DSTATS_DISABLED=1 to CMake to disable)
54 #ifdef STATS_DISABLED
55  #define IF_STATS(x)
57 #else
58  #define IF_STATS(x) x
60 #endif
61 
62 namespace tdc {
64  template<typename T, class X = void>
65  struct FastIntType {
66  // <not defined>
67  };
68  template<size_t N>
69  struct FastIntType<uint_impl_t<N>, std::enable_if_t<(N <= 32)>> {
70  using Type = uint32_t;
71  };
72  template<size_t N>
73  struct FastIntType<uint_impl_t<N>, std::enable_if_t<(N > 32)>> {
74  using Type = uint64_t;
75  };
76  template<>
77  struct FastIntType<uint32_t> {
78  using Type = uint32_t;
79  };
80  template<>
81  struct FastIntType<uint64_t> {
82  using Type = uint64_t;
83  };
85 
88  template<typename actual_type>
89  using fast_t = typename FastIntType<actual_type>::Type;
90 
100 #ifdef LEN_BITS
102 #else
103  using len_compact_t = uint32_t;
104 #endif
105 
115 
117  constexpr size_t INDEX_MAX = std::numeric_limits<len_compact_t>::max();
118 
121  constexpr size_t INDEX_BITS = 8 * sizeof(len_compact_t);
122 
124  constexpr size_t INDEX_FAST_MAX = std::numeric_limits<len_t>::max();
125 
128  constexpr size_t INDEX_FAST_BITS = 8 * sizeof(len_t);
129 
131  typedef uint8_t uliteral_t;
132 
134  constexpr size_t ULITERAL_MAX = std::numeric_limits<uliteral_t>::max();
135 
141  template<typename T = size_t>
142  constexpr T literal2int(uliteral_t c) {
143  return std::make_unsigned_t<T>(c);
144  }
145 
151  template<typename T = size_t>
152  constexpr uliteral_t int2literal(const T& c) {
153  return std::make_unsigned_t<T>(c);
154  }
155 }
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
uint8_t uliteral_t
Type to represent signed single literals.
Definition: def.hpp:131
constexpr T literal2int(uliteral_t c)
Converts a literal to an integer value as if unsigned.
Definition: def.hpp:142
constexpr size_t INDEX_FAST_MAX
The maximum value of len_t.
Definition: def.hpp:124
typename uint_dispatch_t< N >::type uint_t
Definition: uint_t.hpp:165
constexpr size_t ULITERAL_MAX
The maximum value of uliteral_t.
Definition: def.hpp:134
uint32_t len_compact_t
Type to represent an bit-compact length value.
Definition: def.hpp:103
constexpr size_t INDEX_BITS
The amount of bits required to store the binary representation of a value of type len_compact_t...
Definition: def.hpp:121
fast_t< len_compact_t > len_t
Type to represent an length value.
Definition: def.hpp:114
constexpr size_t INDEX_MAX
The maximum value of len_compact_t.
Definition: def.hpp:117
typename FastIntType< actual_type >::Type fast_t
Type to represent integer values in the size range of actual_type that may require more Bits than it...
Definition: def.hpp:89
constexpr size_t INDEX_FAST_BITS
The amount of bits required to store the binary representation of a value of type len_t...
Definition: def.hpp:128
constexpr uliteral_t int2literal(const T &c)
Converts an integer value to a literal as if unsigned.
Definition: def.hpp:152