SDSL: Succinct Data Structure Library
A C++ template library for succinct data structures
|
00001 /* sdsl - succinct data structures library 00002 Copyright (C) 2010 Simon Gog 00003 00004 This program is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program. If not, see http://www.gnu.org/licenses/ . 00016 */ 00021 #ifndef INCLUDED_SDSL_LCP_CONSTRUCT 00022 #define INCLUDED_SDSL_LCP_CONSTRUCT 00023 00024 #include "typedefs.hpp" // includes definition of tMSS 00025 #include "int_vector.hpp" 00026 #include "rank_support_v.hpp" 00027 #include "util.hpp" 00028 #include "testutils.hpp" 00029 #include "isa_construct.hpp" 00030 #include "bwt_construct.hpp" 00031 00032 #include <iostream> 00033 #include <stdexcept> 00034 #include <list> 00035 #include <algorithm> 00036 #include <fstream> 00037 #include <queue> 00038 #include <list> 00039 00040 //#define STUDY_INFORMATIONS 00041 00042 namespace sdsl 00043 { 00044 00046 00053 bool construct_lcp_kasai(tMSS& file_map, const std::string& dir, const std::string& id); 00054 00055 // semi extern PHI algorithm of Karkainen, Manzini and Puglisi CPM 2009 00056 bool construct_lcp_semi_extern_PHI(tMSS& file_map, const std::string& dir, const std::string& id); 00057 00059 00067 bool construct_lcp_PHI(tMSS& file_map, const std::string& dir, const std::string& id, bool semi_external=false); 00068 00069 class buffered_char_queue 00070 { 00071 typedef bit_vector::size_type size_type; 00072 typedef std::queue<uint8_t> tQ; 00073 private: 00074 static const uint32_t m_buffer_size = 10000;//409600; 00075 uint8_t m_write_buf[m_buffer_size]; 00076 uint8_t m_read_buf[m_buffer_size]; 00077 size_type m_widx; // write index 00078 size_type m_ridx; // read index 00079 bool m_sync; // are read and write buffer the same? 00080 size_type m_disk_buffered_blocks; // number of blocks written to disk and not read again yet 00081 char m_c; 00082 size_type m_rb; // read blocks 00083 size_type m_wb; // written blocks 00084 00085 std::string m_file_name; 00086 00087 std::fstream m_stream; 00088 00089 public: 00090 00091 buffered_char_queue(); 00092 void init(const std::string& dir, char c); 00093 ~buffered_char_queue(); 00094 void push_back(uint8_t x); 00095 uint8_t pop_front(); 00096 }; 00097 00098 typedef std::list<int_vector<>::size_type> tLI; 00099 typedef std::vector<int_vector<>::size_type> tVI; 00100 00101 template<class size_type_class> 00102 void push_front_m_index(size_type_class i, uint8_t c, tLI(&m_list)[256], uint8_t (&m_chars)[256], size_type_class& m_char_count) 00103 { 00104 if (m_list[c].empty()) { 00105 m_chars[m_char_count++] = c; 00106 } 00107 m_list[c].push_front(i); 00108 } 00109 00110 template<class size_type_class> 00111 void push_back_m_index(size_type_class i, uint8_t c, tLI(&m_list)[256], uint8_t (&m_chars)[256], size_type_class& m_char_count) 00112 { 00113 if (m_list[c].empty()) { 00114 m_chars[m_char_count++] = c; 00115 } 00116 m_list[c].push_back(i); 00117 } 00118 00119 // only phase 1 of the new algorithm 00120 bool construct_lcp_simple_5n(tMSS& file_map, const std::string& dir, const std::string& id); 00121 00122 // only phase 2 of the new algorithm 00123 // TODO: assert n > 0 00124 bool construct_lcp_simple2_9n(tMSS& file_map, const std::string& dir, const std::string& id); 00125 00127 00134 bool construct_lcp_go(tMSS& file_map, const std::string& dir, const std::string& id); 00135 00137 00144 bool construct_lcp_goPHI(tMSS& file_map, const std::string& dir, const std::string& id); 00145 00147 00154 bool construct_lcp_go2(tMSS& file_map, const std::string& dir, const std::string& id); 00155 00156 void lcp_info(tMSS& file_map); 00157 00158 }// end namespace 00159 00160 #endif