Structure for storing three columns and quickly searching for a row in any of the columns

We had one hash table as a reference link to a list of values ​​like this:

internal static readonly Hashtable relationcodeAcodeB = new Hashtable
{
    {"149", "23"},
    {"139", "17"}
}

Now we need a structure that can contain 3 values ​​(columns) and quickly search for a value by any of the other two.

Something like that:

internal static readonly Hashtable relationcodeAcodeBcodeC = new Hashtable
{
    {"149", "23", "xx"},
    {"139", "17", "xxx"}
}
string codeB=relationcodeAcodeBcodeC[codeA="149"]["codeB"];
+5
source share
1 answer

Say that your object has three properties codeA, codeB and codeC, you support three hash tables, for example:

Dictionary<string, MyObj> dictA, dictB, dictC;

When creating a new one, MyObjyou add it to three dictionaries:

dictA[obj.codeA] = obj;
dictB[obj.codeB] = obj;
dictC[obj.codeC] = obj;

The look is very simple. Your example will be encoded asdictA["149"].codeB

Keep everything in order in one big search class, of course.

+2
source

All Articles