Sort FingerPrints to remove the need for random access into them.

Random access into FingerPrints and FingerTests using gettestbyname and
getattrbyname was taking non-negligible time when multiplied by the
number of fingerprints in the database. Instead, sort the tests by name
and sort the attributes within each test. We may then compare two lists
by walking both of them in order, not having to look up the same element
twice.
This commit is contained in:
david 2012-01-01 13:24:57 +00:00
parent c07b38c12f
commit cb8d701bf4
3 changed files with 128 additions and 89 deletions

View file

@ -159,6 +159,10 @@ struct ftpinfo {
struct AVal {
const char *attribute;
const char *value;
bool operator<(const AVal& other) const {
return strcmp(attribute, other.attribute) < 0;
}
};
struct OS_Classification {
@ -186,6 +190,10 @@ struct FingerTest {
const char *name;
std::vector<struct AVal> results;
const struct AVal *getattrbyname(const char *name) const;
bool operator<(const FingerTest& other) const {
return strcmp(name, other.name) < 0;
}
};
struct FingerPrint {
@ -193,6 +201,7 @@ struct FingerPrint {
std::vector<FingerTest> tests;
const FingerTest *gettestbyname(const char *name) const;
FingerPrint();
void sort();
};
/* This structure contains the important data from the fingerprint