I need to create a simple lookup function for a program and want to confirm the best way to accomplish the task. I have a two-column CSV file that represents a string (key) and double (value) pair. The list is about 3,000 rows / key-value pairs. I will be doing about 5,000 lookups on this table each time my program is executed. Some psuedo-code is below followed by a few questions:
CSV file - columns are "Tenant" and "PD"
// Declare an unordered map
unordered_map<string,double> TenantPDLookup;
// Read from CSV file into the map object - I can do this part
void ReadTenantLookup(unordered_map<string,double> TenantPDLookup) {...}
// Lookup the values (PD) based on a series of keys (Tenant)
// Here is my code that is not working (note this is a type string, string)
string GetTenantRating(string const& TenantName, Assumptions& Ass,
tenant_lookup_map const& TenantRatingLookup) {
auto TenantRating = TenantRatingLookup.find(TenantName);
if (TenantRating == TenantRatingLookup.end())
return Ass.DefaultTenantRating;
return TenantRating->second;
}
My questions about how to implement this are as follows:
- How do I do the actual lookup? I am thinking a simple function that returns the value when passed (a) a reference to my map and (b) a key. Can someone provide a simple framework
- My string values are "orderable" in the sense that they are alpha terms - should I somehow make this into an ordered list to facilitate faster lookups?
- Does this approach make sense?