tudocomp
– The TU Dortmund Compression Framework
Range.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tudocomp/def.hpp>
4 #include <limits>
5 
6 namespace tdc {
16  class Range {
17  private:
18  size_t m_min;
19  size_t m_max;
20 
21  public:
24  inline constexpr Range(size_t max)
25  : m_min(0), m_max(max) {
26  }
27 
31  inline constexpr Range(size_t min, size_t max)
32  : m_min(min), m_max(max) {
33  }
34 
37  inline size_t min() const { return m_min; }
38 
41  inline size_t max() const { return m_max; }
42 
47  inline size_t delta() const { return m_max - m_min; }
48  };
49 
56  class MinDistributedRange : public Range {
57  public:
60  inline constexpr MinDistributedRange(size_t max) : Range(0, max) {
61  }
62 
66  inline constexpr MinDistributedRange(size_t min, size_t max)
67  : Range(min, max) {
68  }
69  };
70 
73  template<typename T>
74  class TypeRange : public Range {
75  public:
77  inline constexpr TypeRange() : Range(0, std::numeric_limits<T>::max()) {
78  }
79  };
80 
82  template<size_t t_min, size_t t_max>
83  class FixedRange : public Range {
84  public:
86  inline constexpr FixedRange() : Range(t_min, t_max) {}
87  };
88 
90  class LiteralRange : public TypeRange<uliteral_t> {
91  public:
92  inline constexpr LiteralRange() : TypeRange<uliteral_t>() {}
93  };
94 
96  class LengthRange : public TypeRange<len_t> {
97  public:
98  inline constexpr LengthRange(): TypeRange<len_t>() {}
99  };
100 
103 
105  constexpr auto size_r = TypeRange<size_t>();
106 
108  constexpr auto bit_r = BitRange();
109 
111  constexpr auto literal_r = LiteralRange();
112  constexpr auto uliteral_r = LiteralRange();
113 
115  constexpr auto len_r = LengthRange();
116 }
117 
Represents a generic range of positive integers.
Definition: Range.hpp:16
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
size_t delta() const
Yields the difference between the range&#39;s minimum and maximum values.
Definition: Range.hpp:47
Represents the range of valid tdc::uliteral_t values.
Definition: Range.hpp:90
Represents a compiler-level fixed range.
Definition: Range.hpp:83
constexpr auto bit_r
Global predefined range for bits (0 or 1).
Definition: Range.hpp:108
constexpr Range(size_t min, size_t max)
Constructs a range.
Definition: Range.hpp:31
constexpr auto size_r
Global predefined range for the size_t.
Definition: Range.hpp:105
uint8_t uliteral_t
Type to represent signed single literals.
Definition: def.hpp:131
constexpr Range(size_t max)
Constructs a range from zero to a maximum value.
Definition: Range.hpp:24
Represents a range of valid values for a certain type.
Definition: Range.hpp:74
Represents a range of positive integers that tend to be distributed towards the minimum.
Definition: Range.hpp:56
constexpr FixedRange()
Constructs a range with the fixed values.
Definition: Range.hpp:86
size_t max() const
Yields the range&#39;s maximum value.
Definition: Range.hpp:41
FixedRange< 0, 1 > BitRange
Represents the range of bit values, ie 0 to 1
Definition: Range.hpp:102
size_t min() const
Yields the range&#39;s minimum value.
Definition: Range.hpp:37
constexpr auto literal_r
Global predefined reange for literals.
Definition: Range.hpp:111
constexpr LiteralRange()
Definition: Range.hpp:92
fast_t< len_compact_t > len_t
Type to represent an length value.
Definition: def.hpp:114
constexpr auto uliteral_r
Definition: Range.hpp:112
constexpr LengthRange()
Definition: Range.hpp:98
Represents the range of valid tdc::len_t values.
Definition: Range.hpp:96
constexpr auto len_r
Global predefined range for len_t.
Definition: Range.hpp:115
constexpr TypeRange()
Constructs a range for the type.
Definition: Range.hpp:77
constexpr MinDistributedRange(size_t min, size_t max)
Constructs a range.
Definition: Range.hpp:66
constexpr MinDistributedRange(size_t max)
Constructs a range from zero to a maximum value.
Definition: Range.hpp:60