当键和值同等重要的数据结构 [英] Data structure for when key and value are equally "important"

查看:125
本文介绍了当键和值同等重要的数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这可能是一个愚蠢的问题,但是我将唯一的ID映射到唯一的值。有时我想要一个ID的值,有时我想知道一个值的ID。我搜索超过我修改的集合。我想知道是否有一个特殊的数据结构在这里是有意义的,或者如果我应该保持两个副本的集合(从来不是超大的) - 一个由ID键入的值,另一个由值键入。



谢谢!

解决方案

维护两个副本的集合是规范的解决方案。请注意,如果合适,两个方向可以使用不同的集合类型(例如,具有不同散列函数的散列表,散列表和平衡树等)。


So, this is probably a stupid question, but I have a mapping of unique IDs to unique values. Sometimes I want the value for a certain ID, sometimes I want to know the ID of a certain value. I search more than I modify the collection. I'm wondering if there's a special datastructure that makes sense here, or if I should just maintain two copies of the collection (which is never super large)--one keyed by ID, and one keyed by value.

Thanks!

解决方案

Maintaining two copies of the collection is the canonical solution.

Note that the two directions can use different collection types if appropriate (e.g. hash tables with different hash functions, a hash table and a balanced tree, etc.).

这篇关于当键和值同等重要的数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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