tudocomp
– The TU Dortmund Compression Framework
EliasGammaCoder.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tudocomp/Coder.hpp>
4 
5 namespace tdc {
6 
11 class EliasGammaCoder : public Algorithm {
12 public:
13  inline static Meta meta() {
14  Meta m("coder", "gamma", "Elias-gamma encoding");
15  return m;
16  }
17 
18  EliasGammaCoder() = delete;
19 
21  class Encoder : public tdc::Encoder {
22  public:
25 
26  template<typename value_t>
27  inline void encode(value_t v, const Range&) {
28  m_out->write_elias_gamma(v);
29  }
30  };
31 
33  class Decoder : public tdc::Decoder {
34  public:
37 
38  template<typename value_t>
39  inline value_t decode(const Range&) {
40  return m_in->read_elias_gamma<value_t>();
41  }
42  };
43 };
44 
45 }
46 
Represents a generic range of positive integers.
Definition: Range.hpp:16
Encoder(Env &&env, std::shared_ptr< BitOStream > out, literals_t &&literals)
Constructor.
Definition: Coder.hpp:29
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
Provides meta information about an Algorithm.
Definition: Meta.hpp:34
Encodes data to a stream of Elias-Gamma codes.
void encode(value_t v, const Range &)
Defines data encoding to and decoding from a stream of Elias-Gamma codes.
std::shared_ptr< BitOStream > m_out
The underlying bit output stream.
Definition: Coder.hpp:18
value_t decode(const Range &r)
Decodes an arbitrary-range integer value.
Definition: Coder.hpp:127
Decoder(Env &&env, std::shared_ptr< BitIStream > in)
Constructor.
Definition: Coder.hpp:98
Base for data encoders.
Definition: Coder.hpp:14
value_t decode(const Range &)
void encode(value_t v, const Range &r)
Encodes an arbitrary-range integer value.
Definition: Coder.hpp:61
Base for data decoders.
Definition: Coder.hpp:87
Interface for algorithms.
Definition: Algorithm.hpp:15
Decodes data from a stream of Elias-Gamma codes.