views:

54

answers:

1

ENVIRONMENT: C#

I have a table of equivalent values, like this:

CHEVR = CHEVROLET
MERCE = MERCEDES
ALFA = ALFA ROMEO
[...]

I have this data in a tab delimited file.

I also have a table with about 15M rows, which contains informations about car parts. One of these is the first row from the equivalent values table (CHEVR, MERCE, ALFA, etc...). Ex:

ID         NAME          MODEL          ORD
1         PART 1         CHEVR         0001
2         PART 2         MERCE         0002
[...]

THE AIM: I need to generate a new table by joining the two tables and replace the short name of the car model to the long one:

ID        NAME         MODEL              ORD
1         PART 1        CHEVROLET         0001
2         PART 2        MERCEDES          0002

QUESTION: What is the best (optimal) way to store the first table (equivalent values) as I go through the car parts table with a while cicle and I don't want to open the file and search for the SHORT NAME in each step (15M times).

In PHP for example you can store arrays like: $arr['CHEVR'] = "CHEVROLET"; This would be the best way in PHP. Which is it in C#?

+1  A: 

You can use Dictionary where the key is the short name and the value is the full name. The access to each item is O(1) amortized.

var map = new Dictionary<string, string>();
map.Add("CHEVR", "CHEVROLET");

string fullName = map["CHEVR"];
Elisha