data structure

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
C

csharpula csharp

Hello,
I would like to use a two ways data structure. Such as hash table that
will provide me a mapping but to both sides and not only one side as it
is in hash table. Is there such data structure in c#?
Thank u!
 
Hello,
I would like to use a two ways data structure. Such as hash table that
will provide me a mapping but to both sides and not only one side as it
is in hash table. Is there such data structure in c#?

No, but there's nothing to stop you from using two Dictionary
instances together to achieve the same effect, and even wrapping them
in your own class to ensure that they always remain consistent.
 
And how will I bound the two dictionaries for this purpose?
How to implement this?

Thanks.
 
csharpula said:
And how will I bound the two dictionaries for this purpose?
How to implement this?

Thanks.

You just put two dictionaries in a class, and when you add an item, add
it to both dictionaries.

Starting point:

class DoubleDictionary<Key, Value> {

private Dictionary<Key, Value> _values = new Dictionary<Key, Value>();
private Dictionary<Value, Key> _keys = new Dictionary<Value, Key>();

public void Add(Key key, Value value) {
_values.Add(key, value);
_keys.Add(value, key);
}

public Value GetByKey(Key key) {
return _values[key];
}

public Key GetByValue(Value value) {
return _keys[value];
}

}
 
Back
Top