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

查看:35
本文介绍了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天全站免登陆