Java是否具有反向查找的HashMap? [英] Does Java have a HashMap with reverse lookup?

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

问题描述

我的数据是按照键 - 键格式组织的,而不是键值。这就像一个HashMap,但是我需要在两个方向上进行O(1)查找。这种类型的数据结构是否有名称,Java标准库中是否包含这样的内容? (或者可能是Apache Commons?)

I have data that is organized in kind of a "key-key" format, rather than "key-value". It's like a HashMap, but I will need O(1) lookup in both directions. Is there a name for this type of data structure, and is anything like this included in Java's standard libraries? (or maybe Apache Commons?)

我可以编写自己的类,基本上使用两个镜像地图,但我宁愿不重新发明轮(如果这已经存在,我只是不寻找正确的术语)。

I could write my own class that basically uses two mirrored Maps, but I'd rather not reinvent the wheel (if this already exists but I'm just not searching for the right term).

推荐答案

Java API中没有这样的类。您想要的Apache Commons类将成为 BidiMap

There is no such class in the Java API. The Apache Commons class you want is going to be one of the implementations of BidiMap.

作为一名数学家,我将这种结构称为双射。

As a mathematician, I would call this kind of structure a bijection.

这篇关于Java是否具有反向查找的HashMap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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