收藏需要两个键,一个独特的价值 [英] Collection requiring two keys to a unique value

查看:114
本文介绍了收藏需要两个键,一个独特的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道存储这样的,它将与两个键索引数据的好办法。基本上,我需要的东西就像一个表(顶行键1,左列是密钥2,信件是值从索引返回):

I was wondering if anyone knew a good way to store data such that it would be indexed with two keys. Basically, I need something like a table (top-row is key1, left-column is key2, letters are values returned from indexing):

[ ] [1] [2] [3] [4]
[1] [A] [B] [C] [D]
[2] [B] [E] [F] [G]
[3] [C] [F] [H] [I]
[4] [D] [G] [I] [J]

我可以很容易地实现这个作为一个多维数组,但是因为一半的表始终是相同的,这似乎是多余的。到目前为止,我可以想出的最佳解决方案涉及到一个2维列表,所述第二尺寸为可变长度,同时迫使或较大或两个键的小首先被编入索引。这将打开该表分为:

I could easily implement this as a multidimensional array, but since half the table is always identical, it seemed redundant. So far, the best solution I can come up with involves a 2 Dimensional list, with the second dimension being a variable length, while forcing either the larger or the smaller of the two keys to be indexed first. This turns the table into:

[ ] [1] [2] [3] [4]
[1] [A]
[2] [B] [E]
[3] [C] [F] [H]
[4] [D] [G] [I] [J]

没有人有任何更好的想法?

Does anyone have any better ideas?

编辑:我可能已经想通了,我自己的解决方案。见注释

I may have figured out a solution on my own. See comments.

推荐答案

我建议:

Dictionary<Tuple<int, int>, char>



除非你的表将非常大。

unless your table will be very large.

这篇关于收藏需要两个键,一个独特的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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