双射词典/地图在C# [英] Bijective Dictionary /Map in C#

查看:145
本文介绍了双射词典/地图在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有有效的存储键/值对,其中键和值是不同的,因此,双射映射(即TryGetValue / TryGetKey)是可能的双射字典in.NET?天真的方法是有两个内置的字典:一个键值和值密钥字典,但这不是有效的在内存方面

Is there a bijective dictionary in.NET that efficiently stores Key/Values pairs, where both keys and values are distinct, so a bijective mapping (i.e. TryGetValue/TryGetKey) is possible? The naive approach would be to have two internal dictionaries: A key-value and a value-key dictionary, but this is not efficient in terms of memory.

推荐答案

我不相信有一在.NET。根据不同的键/值类型,我不知道该使用两个字典有可能造成的的多大的效率损失:这是我会做什么,直到我看到了问题的基础上,事实上,它是简单的。

I don't believe there's one in .NET. Depending on the key/value types, I'm not sure that using two dictionaries is likely to cause that much of an efficiency loss: it's what I'd do until I saw a problem, based on the fact that it's simple.

在事实上,它的非常的简单,因为我已经在另一个堆栈溢出的答案付诸实施。我去看看我能找到它...

In fact, it's very simple as I've already implemented it in another Stack Overflow answer. I'll see if I can find it...

编辑:我发现了两个:

  • One of mine
  • Another based on mine, but more fully developed with Remove etc.

这篇关于双射词典/地图在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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