data structure

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!
 
P

Pavel Minaev

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.
 
C

csharpula csharp

And how will I bound the two dictionaries for this purpose?
How to implement this?

Thanks.
 
G

Göran Andersson

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];
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top