From 744ed997a9425296ab41f75515714fa858ebe606 Mon Sep 17 00:00:00 2001 From: Rick Altherr Date: Mon, 20 Nov 2017 16:40:48 -0800 Subject: [PATCH] segmatch: add options to exclude tags and bits from a database --exclude_known will omit any tags and bits that are already saved in the database specified with --database_path. Signed-off-by: Rick Altherr Signed-off-by: Tim 'mithro' Ansell --- tools/CMakeLists.txt | 2 +- tools/segmatch.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 3ed54a99..8549e2fc 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,4 +2,4 @@ add_executable(bitread bitread.cc) target_link_libraries(bitread gflags absl::strings) add_executable(segmatch segmatch.cc) -target_link_libraries(segmatch gflags absl::strings) +target_link_libraries(segmatch libprjxray gflags absl::strings) diff --git a/tools/segmatch.cc b/tools/segmatch.cc index 1593e483..af379fda 100644 --- a/tools/segmatch.cc +++ b/tools/segmatch.cc @@ -13,6 +13,7 @@ #include #include +#include DEFINE_int32(c, 4, "threshold under which candidates are output. set to -1 to output all."); DEFINE_bool(i, false, "add inverted tags"); @@ -20,6 +21,9 @@ DEFINE_int32(m, 0, "min number of set/cleared samples each"); DEFINE_int32(M, 0, "min number of set/cleared samples total"); DEFINE_string(o, "", "set output file"); DEFINE_string(k, "", "set output mask file"); +DEFINE_string(database_path, "", "path to root directory of a database"); +DEFINE_bool(exclude_known, false, "exclude tags and bits recorded in the " + "database specified by --database"); using std::map; using std::tuple; @@ -138,6 +142,9 @@ static inline bool_vec &segdata_bits(segdata_t &sd) { return std::get<0>(sd); } static inline bool_vec &segdata_tags1(segdata_t &sd) { return std::get<1>(sd); } static inline bool_vec &segdata_tags0(segdata_t &sd) { return std::get<2>(sd); } +std::set exclude_tags; +std::set exclude_bits; + void read_input(std::istream &f, std::string filename) { string token; @@ -167,6 +174,10 @@ void read_input(std::istream &f, std::string filename) assert(segptr != nullptr); f >> token; + + if (exclude_bits.find(token) == exclude_bits.end()) + continue; + if (bit_ids.count(token) == 0) { bit_ids[token] = num_bits++; bit_ids_r.push_back(token); @@ -184,6 +195,13 @@ void read_input(std::istream &f, std::string filename) assert(segptr != nullptr); f >> token; + + if (exclude_tags.find(token) == exclude_tags.end()) { + // Consume the rest of the line. + f >> token; + continue; + } + if (tag_ids.count(token) == 0) { tag_ids[token] = num_tags++; tag_ids_r.push_back(token); @@ -236,6 +254,19 @@ int main(int argc, char **argv) absl::StrCat("Usage: ", argv[0], " [options] file..")); gflags::ParseCommandLineFlags(&argc, &argv, true); + if (!FLAGS_database_path.empty()) { + prjxray::Database database(FLAGS_database_path); + + if (FLAGS_exclude_known) { + for (auto& segbits : database.segbits()) { + for (auto tag_bit : *segbits) { + exclude_tags.emplace(tag_bit.tag()); + exclude_bits.emplace(tag_bit.bit()); + } + } + } + } + if (argc > 1) { for (int optind = 1; optind < argc; optind++) { printf("Reading %s.\n", argv[optind]);