SDSL: Succinct Data Structure Library
A C++ template library for succinct data structures
|
00001 #ifndef INCLUDED_SDSL_WT_HELPER 00002 #define INCLUDED_SDSL_WT_HELPER 00003 00004 #include "int_vector.hpp" 00005 00006 namespace sdsl 00007 { 00008 00009 const uint16_t _undef_node = 65535; 00010 00012 00015 template<class size_type_class, class size_type> 00016 void calculate_character_occurences(int_vector_file_buffer<8, size_type_class>& text, const size_type size, size_type* C) 00017 { 00018 text.reset(); 00019 if (text.int_vector_size < size) { 00020 throw std::logic_error("calculate_character_occurences: stream size is smaller than size!"); 00021 return; 00022 } 00023 for (size_type i=0, r_sum=0, r = text.load_next_block(); r_sum < size;) { 00024 if (r_sum + r > size) { // read not more than size chars in the next loop 00025 r = size-r_sum; 00026 } 00027 for (; i < r_sum+r; ++i) { 00028 ++C[text[i-r_sum]]; 00029 } 00030 r_sum += r; r = text.load_next_block(); 00031 } 00032 } 00033 00034 template<class size_type> 00035 void calculate_effective_alphabet_size(const size_type* C, size_type& sigma) 00036 { 00037 sigma = 0; // initialize with 0 00038 for (size_type i=0; i < 256; ++i) // for all possible symbols 00039 if (C[i] > 0) // increase sigma, if it 00040 ++sigma; // exists in the text 00041 } 00042 00043 } // end namespace sdsl 00044 #endif