From 2841137f8e78c6dd3f2d31d982afa4fed0fea741 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Tue, 30 Apr 2019 19:01:19 +0200 Subject: [PATCH] optimize searching xml tree with hash tables --- lib/tdm_ripper.cpp | 90 +++++++++++++++++++++++++++++++++------------- lib/tdm_ripper.hpp | 56 ++++++++++++++++++++++++++++- main.cpp | 16 ++++----- makefile | 1 + 4 files changed, 128 insertions(+), 35 deletions(-) diff --git a/lib/tdm_ripper.cpp b/lib/tdm_ripper.cpp index bd8f5f7..8eb27ec 100644 --- a/lib/tdm_ripper.cpp +++ b/lib/tdm_ripper.cpp @@ -105,11 +105,45 @@ void tdm_ripper::parse_structure() } } - // extract basic information about available channels + // obtain list of xpointers and ids to assign channels for (pugi::xml_node anode: subtreedata.children()) { if ( std::string(anode.name()).compare("tdm_channel") == 0 ) { + std::string id(anode.attribute("id").value()); + std::string val = get_str_between(anode.child_value("local_columns"),"\"","\""); + xml_local_columns_.insert(std::pair(id,val)); + } + + if ( std::string(anode.name()).compare("localcolumn") == 0 ) + { + std::string id(anode.attribute("id").value()); + std::string val = get_str_between(anode.child_value("values"),"\"","\""); + xml_values_.insert(std::pair(id,val)); + } + + if ( std::string(anode.name()).compare("double_sequence") == 0 ) + { + std::string id(anode.attribute("id").value()); + std::string val = anode.child("values").attribute("external").value(); + xml_double_sequence_.insert(std::pair(id,val)); + } + } + std::cout<<"number of pairs in\n"; + std::cout<> minmax_; + // use xpointers and ids to assign channels to byteoffsets + std::map xml_local_columns_, xml_values_, xml_double_sequence_; + // byteoffset, length and datatype of channels std::vector byteoffset_; std::vector length_; @@ -57,7 +60,7 @@ public: void parse_structure(); - void list_channels(std::ostream& gout = std::cout, int width = 15, int maxshow = 300); + void list_channels(std::ostream& gout = std::cout, int width = 15, int maxshow = 50); void show_structure(); @@ -85,6 +88,57 @@ public: return entirestr.substr(apos+startlim.length(),bpos-(apos+startlim.length())); } + void print_hash_local(const char* filename, int width = 20) + { + std::ofstream fout(filename); + + std::map::iterator it; + int count = 0; + for ( it = xml_local_columns_.begin(); it != xml_local_columns_.end(); it++ ) + { + count++; + fout<first; + fout<second; + fout<<"\n"; + } + fout.close(); + } + + void print_hash_values(const char* filename, int width = 20) + { + std::ofstream fout(filename); + + std::map::iterator it; + int count = 0; + for ( it = xml_values_.begin(); it != xml_values_.end(); it++ ) + { + count++; + fout<first; + fout<second; + fout<<"\n"; + } + fout.close(); + } + + void print_hash_double(const char* filename, int width = 20) + { + std::ofstream fout(filename); + + std::map::iterator it; + int count = 0; + for ( it = xml_double_sequence_.begin(); it != xml_double_sequence_.end(); it++ ) + { + count++; + fout<first; + fout<second; + fout<<"\n"; + } + fout.close(); + } + // provide number of channels and group const int& num_channels() { diff --git a/main.cpp b/main.cpp index 6368899..1c68800 100644 --- a/main.cpp +++ b/main.cpp @@ -11,20 +11,16 @@ int main(int argc, char* argv[]) tdm_ripper ripper(argv[1]); // ripper.list_datatypes(); + // ripper.show_structure(); - // int sn = -76476; - // std::vector bych = ripper.convert_int(sn); - // std::cout<<"length of vector "<