Hello,
I have a vector of custom structs and one of the fields is a key in fixed string format (by fixed I mean no wildcards etc). There are about 50,000 structs or elements in the vector.
struct Item {
field1 : String,
field2: String,
key: String,
}let mut items : Vec = Vec::with_capacity(50_000);
//then push each Item into items
In my program I am reading in a table from a csv file and I am wondering what the most efficient way of taking the key field from each of the Item structs above and finding a match in my csv table. The csv table also has a string key column but this time, the string key contains wildcards.
I was thinking of reading the csv table into a HashMap with the key field as the HashMap key and the value being a struct composed from the fields of each row in the csv file:
struct Row {
field1: String,
field2: String,
key : String //this string field has regex characters and wildcards etc.
}let mut rows : HashMap<String, Row> = HashMap::with_capacity(80_000);
//then push each Row into rows
The reason I was thinking of using a HashMap is for speed of lookup. The only problem is that, I believe a HashMap looks for an exact match of key.
If I take an example of where the key of a particular Item is "abc123" and the key of a row in the HashMap is "ab[cd]123", I would like this to be a match. But I am not sure how I can get the HashMap to match on regexes.
for item in &items {
printlin!("{:?}, &rows.get(item.key)) // "abc123" will not match string literal "ab[cd]123
}
Does anyone have any thoughts or ideas? I am not too sure how I can build regex into the HashMap key or perhaps there is another/better way of searching?
I am trying to avoid a brute force for loop where I take each item in a vector of 50_000 items and then search through a vector of 80_000 rows to find a match. That seems very inefficient!
I hope this question makes sense!