双向字典? [英] Bi-directional dictionary?

查看:185
本文介绍了双向字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两组对象,在某些情况下,第一组将被用作另一组的键,而在其他情况下,第二组将用作第一组的键。此外,任何一个列表中都不能有任何重复项。



这是一个很好的数据结构?我应该使用两个字典,还是有更智能的方式?

解决方案

有更好的数据结构知识的人可能会提供更好的建议,但个人来说,我会使用2个字典来方便使用。你可以使用1个字典做同样的事情,但访问时间会增加。



编辑:废话,我正在写一些代码如何做,我看到Falaina发布了这是一样的想法,我只是做得更好:获取通用词典的价值的钥匙


I have two sets of objects where in some cases the first set will be used as keys for the other set, and in other cases the second set will be used as keys for the first. In addition there must be no duplicates in either list.

What would be a good data-structure to use for this? Should I use two Dictionaries for this or are there smarter ways?

解决方案

Someone with better knowledge of data structures could probably give better advice, but personally, I'd use 2 dictionaries for ease of use. You could do the same with 1 dictionary but access time would increase.

Edit: crap, I was just in the process of writing up some code how I would do it and I saw that Falaina posted this which is the same idea that I was doing only much better: Getting key of value of a generic Dictionary?

这篇关于双向字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆