SDSL 3.0.2
Succinct Data Structure Library
Loading...
Searching...
No Matches
coder.hpp
Go to the documentation of this file.
1// Copyright (c) 2016, the SDSL Project Authors. All rights reserved.
2// Please see the AUTHORS file for details. Use of this source code is governed
3// by a BSD license that can be found in the LICENSE file.
8#ifndef SDSL_CODER
9#define SDSL_CODER
10
11#include <assert.h>
12#include <stdint.h>
13
14// clang-format off
15// Cyclic includes start
16#include <sdsl/coder_comma.hpp>
20// Cyclic includes end
21// clang-format on
22
23namespace sdsl
24{
25
27namespace coder
28{
29
30template <class Coder>
32{
33public:
34 typedef uint64_t size_type;
35 static void encode(uint64_t x, uint64_t *& z, uint8_t offset);
36 static uint64_t encoding_length(uint64_t const * s, uint8_t s_offset, size_type bit_length);
37};
38
39template <class Coder>
41run_length<Coder>::encoding_length(uint64_t const * s, uint8_t s_offset, size_type bit_length)
42{
43 assert(s_offset < 64);
44 size_type i = 0;
45 uint64_t w = (*s >> s_offset);
46 uint8_t last_bit = w & 1;
47 size_type result = 0;
48 while (i < bit_length)
49 {
50 size_type len = 0;
51 while (last_bit == (w & 1) and i < bit_length)
52 {
53 // std::cout<<w<<" "<<i<<std::endl;
54 ++len;
55 ++i;
56 ++s_offset;
57 w >>= 1;
58 if (s_offset == 64)
59 {
60 s_offset = 0;
61 w = *(++s);
62 }
63 }
64 // std::cout<<"len="<<Coder::encoding_length(len)<<std::endl;
65 last_bit = (w & 1);
66 result += Coder::encoding_length(len);
67 }
68 return result;
69}
70
71} // end namespace coder
72
73} // end namespace sdsl
74
75#endif
static uint64_t encoding_length(uint64_t const *s, uint8_t s_offset, size_type bit_length)
Definition coder.hpp:41
static void encode(uint64_t x, uint64_t *&z, uint8_t offset)
coder_comma.hpp contains the class sdsl::coder::comma
coder_elias_delta.hpp contains the class sdsl::coder::elias_delta
coder_elias_gamma.hpp contains the class sdsl::coder::elias_gamma
coder_fibonacci.hpp contains the class sdsl::coder::fibonacci
Namespace for the succinct data structure library.