-
Notifications
You must be signed in to change notification settings - Fork 349
/
coder.hpp
77 lines (65 loc) · 2.26 KB
/
coder.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* sdsl - succinct data structures library
Copyright (C) 2008 Simon Gog
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/ .
*/
/*! \file coder.hpp
\brief coder.hpp contains the coder namespace and includes the header files of sdsl::coder::fibonacci, sdsl::coder::elias_delta, and sdsl::coder::run_length
\author Simon Gog
*/
#ifndef SDSL_CODER
#define SDSL_CODER
#include "int_vector.hpp"
#include "coder_fibonacci.hpp"
#include "coder_elias_delta.hpp"
#include "coder_elias_gamma.hpp"
#include "coder_comma.hpp"
namespace sdsl
{
//! Namespace for the different coder of the sdsl.
namespace coder
{
template<class Coder>
class run_length
{
public:
typedef uint64_t size_type;
static void encode(uint64_t x, uint64_t*& z, uint8_t offset);
static uint64_t encoding_length(const uint64_t* s, uint8_t s_offset, size_type bit_length);
};
template<class Coder>
typename run_length<Coder>::size_type run_length<Coder>::encoding_length(const uint64_t* s, uint8_t s_offset, size_type bit_length)
{
assert(s_offset < 64);
size_type i=0;
uint64_t w = (*s >> s_offset);
uint8_t last_bit = w&1;
size_type result = 0;
while (i < bit_length) {
size_type len = 0;
while (last_bit == (w&1) and i < bit_length) {
// std::cout<<w<<" "<<i<<std::endl;
++len; ++i; ++s_offset;
w >>= 1;
if (s_offset == 64) {
s_offset = 0;
w = *(++s);
}
}
// std::cout<<"len="<<Coder::encoding_length(len)<<std::endl;
last_bit = (w&1);
result += Coder::encoding_length(len);
}
return result;
}
} // end namespace coder
} // end namespace sdsl
#endif