reduce number of needed hash operations

This commit is contained in:
Bernhard Amann 2012-02-20 17:13:41 -08:00
parent edd30da082
commit d5b413c4e7
3 changed files with 8 additions and 21 deletions

View file

@ -782,8 +782,8 @@ int Manager::SendEntryTable(const ReaderFrontend* reader, const int id, const Va
hash_t valhash = 0; hash_t valhash = 0;
if ( filter->num_val_fields > 0 ) { if ( filter->num_val_fields > 0 ) {
HashKey* valhashkey = HashValues(filter->num_val_fields, vals+filter->num_idx_fields); HashKey* valhashkey = HashValues(filter->num_val_fields, vals+filter->num_idx_fields);
valhash = valhashkey->Hash(); valhash = valhashkey->Hash();
delete(valhashkey); delete(valhashkey);
} }
//reporter->Error("Result: %d", (uint64_t) valhash->Hash()); //reporter->Error("Result: %d", (uint64_t) valhash->Hash());
@ -873,19 +873,17 @@ int Manager::SendEntryTable(const ReaderFrontend* reader, const int id, const Va
HashKey* k = filter->tab->ComputeHash(idxval); HashKey* k = filter->tab->ComputeHash(idxval);
if ( !k ) { if ( !k ) {
reporter->InternalError("could not hash"); reporter->InternalError("could not hash");
return filter->num_val_fields + filter->num_idx_fields; assert(false);
} }
InputHash* ih = new InputHash();
ih->idxkey = new HashKey(k->Key(), k->Size(), k->Hash());
ih->valhash = valhash;
if ( filter->event && updated ) if ( filter->event && updated )
Ref(oldval); // otherwise it is no longer accessible after the assignment Ref(oldval); // otherwise it is no longer accessible after the assignment
filter->tab->Assign(idxval, k, valval); filter->tab->Assign(idxval, k, valval);
InputHash* ih = new InputHash();
k = filter->tab->ComputeHash(idxval);
ih->idxkey = k;
ih->valhash = valhash;
//i->tab->Delete(k);
filter->currDict->Insert(idxhash, ih); filter->currDict->Insert(idxhash, ih);
if ( filter->event ) { if ( filter->event ) {
@ -1557,7 +1555,7 @@ HashKey* Manager::HashValues(const int num_elements, const Value* const *vals) {
if ( data == 0 ) { if ( data == 0 ) {
reporter->InternalError("Could not malloc?"); reporter->InternalError("Could not malloc?");
} }
memset(data, 0, length); //memset(data, 0, length);
for ( int i = 0; i < num_elements; i++ ) { for ( int i = 0; i < num_elements; i++ ) {
const Value* val = vals[i]; const Value* val = vals[i];
position += CopyValue(data, position, val); position += CopyValue(data, position, val);
@ -1695,11 +1693,3 @@ Manager::ReaderInfo* Manager::FindReader(const EnumVal* id)
return 0; return 0;
} }
string Manager::Hash(const string &input) {
unsigned char digest[16];
hash_md5(input.length(), (const unsigned char*) input.c_str(), digest);
string out((const char*) digest, 16);
return out;
}

View file

@ -202,8 +202,6 @@ private:
vector<ReaderInfo*> readers; vector<ReaderInfo*> readers;
string Hash(const string &input);
class Filter; class Filter;
class TableFilter; class TableFilter;
class EventFilter; class EventFilter;

View file

@ -302,7 +302,6 @@ Value* Ascii::EntryToVal(string s, FieldMapping field) {
break; break;
case TYPE_PORT: case TYPE_PORT:
val->val.port_val.port = 0;
val->val.port_val.port = atoi(s.c_str()); val->val.port_val.port = atoi(s.c_str());
val->val.port_val.proto = TRANSPORT_UNKNOWN; val->val.port_val.proto = TRANSPORT_UNKNOWN;
break; break;