SDSL 3.0.1
Succinct Data Structure Library
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 <sdsl/coder_comma.hpp>
15#include <sdsl/int_vector.hpp>
16
17namespace sdsl
18{
19
21namespace coder
22{
23
24template <class Coder>
26{
27 public:
28 typedef uint64_t size_type;
29 static void encode(uint64_t x, uint64_t *& z, uint8_t offset);
30 static uint64_t encoding_length(const uint64_t * s, uint8_t s_offset, size_type bit_length);
31};
32
33template <class Coder>
35 uint8_t s_offset,
36 size_type bit_length)
37{
38 assert(s_offset < 64);
39 size_type i = 0;
40 uint64_t w = (*s >> s_offset);
41 uint8_t last_bit = w & 1;
42 size_type result = 0;
43 while (i < bit_length)
44 {
45 size_type len = 0;
46 while (last_bit == (w & 1) and i < bit_length)
47 {
48 // std::cout<<w<<" "<<i<<std::endl;
49 ++len;
50 ++i;
51 ++s_offset;
52 w >>= 1;
53 if (s_offset == 64)
54 {
55 s_offset = 0;
56 w = *(++s);
57 }
58 }
59 // std::cout<<"len="<<Coder::encoding_length(len)<<std::endl;
60 last_bit = (w & 1);
61 result += Coder::encoding_length(len);
62 }
63 return result;
64}
65
66} // end namespace coder
67
68} // end namespace sdsl
69
70#endif
static uint64_t encoding_length(const uint64_t *s, uint8_t s_offset, size_type bit_length)
Definition: coder.hpp:34
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
int_vector.hpp contains the sdsl::int_vector class.
Namespace for the succinct data structure library.