File: EnumCoder.hpp

package info (click to toggle)
rapmap 0.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,428 kB
  • ctags: 3,173
  • sloc: cpp: 16,065; ansic: 3,471; sh: 153; python: 82; makefile: 8
file content (53 lines) | stat: -rw-r--r-- 1,801 bytes parent folder | download | duplicates (6)
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
/* 
 *  Copyright (c) 2012 Daisuke Okanohara
 * 
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 * 
 *   1. Redistributions of source code must retain the above Copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above Copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 *   3. Neither the name of the authors nor the names of its contributors
 *      may be used to endorse or promote products derived from this
 *      software without specific prior written permission.
 */

#ifndef RSDIC_ENUM_CODER_HPP_
#define RSDIC_ENUM_CODER_HPP_

#include <stdint.h>
#include "Const.hpp"

namespace rsdic{

class EnumCoder{
public:
  static uint64_t Encode(uint64_t val, uint64_t rank_sb);
  static uint64_t Decode(uint64_t code, uint64_t rank_sb);
  static bool GetBit(uint64_t code, uint64_t rank_sb, uint64_t pos);
  static uint64_t Rank(uint64_t code, uint64_t rank_sb, uint64_t pos);
  static uint64_t Select(uint64_t code, uint64_t rank_sb, uint64_t num, bool bit);

  static uint64_t Len(uint64_t rank_sb){
    return kEnumCodeLength_[rank_sb];
  }

  static uint64_t Select0(uint64_t code, uint64_t rank_sb, uint64_t num);
  static uint64_t Select1(uint64_t code, uint64_t rank_sb, uint64_t num);

private:
  static uint64_t PopCount(uint64_t code);
  static uint64_t SelectRaw(uint64_t code, uint64_t num);
  static const uint8_t kPopCount_[256];
  static const uint64_t kCombinationTable64_[65][65];
  static const uint8_t kEnumCodeLength_[65];
};

}

#endif // RSDIC_ENUM_CODER_HPP_