Hi all,
I have conversion tables I need to contain in memory for fast access. Until now I used a simple Hashtable
were the Key was the internal code, and the Value was an object holding the external code and other meta-data.
Now we need to have a reverse look-up, meaning to get the internal code based on the external code. I could only come up with the following options:
- Have another container for this look-up, Hashtable containing only the internal code as Value to prevent more redundancy.
- Use the same container I use now, and store those objects again now using the the external code as the Key (have a prefix to prevent collisions).
- Don't pull data using Keys, but iterate through the Values contained under the same container to find the requested object ( O(n), same memory usage ).
The container is being lazy-loaded, so options 1&2 usually won't perform under the worst-case scenario.
Thoughts anyone? Please tell me there's some efficient container I could use for that, which I missed!
* EDIT *
Being a GC'd framework, and accepting the fact I'd have to have two conversion arrays (Dictionaries), would the following lines of code actually mean I stored only one object on memory, and then two pointers for it, under two different hashed-cells?
Dictionary<K1,V> forward;
Dictionary<K2,V> reverse;
//...
void Add(V myObject)
{
// myObject being the BLL object
forward.Add(myObject.InternalCode, myObject);
reverse.Add(myObject.ExternalCode, myObject);
}
Itamar.