10 #ifndef WT_PREFIX_COUNTING 11 #define WT_PREFIX_COUNTING 18 template <
typename AlphabetType,
typename SizeType>
22 template<
typename text_t>
23 wt_pc(
const text_t& text,
const SizeType size,
24 const SizeType levels) : _bv(levels) {
26 SizeType cur_max_char = (1 << levels);
27 std::vector<SizeType> s_pos(cur_max_char, 0);
28 std::vector<SizeType> hist(cur_max_char, 0);
29 std::vector<SizeType> borders(cur_max_char, 0);
31 _bv[0] =
new uint64_t[(size + 63ULL) >> 6];
32 memset(_bv[0], 0, ((size + 63ULL) >> 6) *
sizeof(uint64_t));
35 for (; cur_pos + 64 <= size; cur_pos += 64) {
37 for (SizeType i = 0; i < 64; ++i) {
38 ++hist[text[cur_pos + i]];
40 word |= ((text[cur_pos + i] >> (levels - 1)) & 1ULL);
42 _bv[0][cur_pos >> 6] = word;
46 for (SizeType i = 0; i < size - cur_pos; ++i) {
47 ++hist[text[cur_pos + i]];
49 word |= ((text[cur_pos + i] >> (levels - 1)) & 1ULL);
51 word <<= (64 - (size & 63ULL));
52 _bv[0][size >> 6] = word;
55 for (SizeType level = levels - 1; level > 0; --level) {
56 const SizeType prefix_shift = (levels - level);
57 const SizeType cur_bit_shift = prefix_shift - 1;
59 _bv[level] =
new uint64_t[(size + 63ULL) >> 6];
60 memset(_bv[level], 0, ((size + 63ULL) >> 6) *
sizeof(uint64_t));
63 for (SizeType i = 0; i < cur_max_char; ++i) {
64 hist[i] = hist[i << 1] + hist[(i << 1) + 1];
68 for (SizeType i = 1; i < cur_max_char; ++i) {
69 borders[i] = borders[i - 1] + hist[i - 1];
72 for (SizeType i = 0; i < size; ++i) {
73 const SizeType
pos = borders[text[i] >> prefix_shift]++;
74 _bv[level][pos >> 6] |= (((text[i] >> cur_bit_shift) & 1ULL)
75 << (63ULL - (pos & 63ULL)));
85 std::vector<uint64_t*> _bv;
90 #endif // WT_PREFIX_COUNTING