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 <kc8apf@kc8apf.net>
Signed-off-by: Tim 'mithro' Ansell <mithro@mithis.com>
This commit is contained in:
Rick Altherr 2017-11-20 16:40:48 -08:00 committed by Tim 'mithro' Ansell
parent 51b586365b
commit 744ed997a9
2 changed files with 32 additions and 1 deletions

View File

@ -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)

View File

@ -13,6 +13,7 @@
#include <absl/strings/str_cat.h>
#include <gflags/gflags.h>
#include <prjxray/database.h>
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<std::string> exclude_tags;
std::set<std::string> 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]);