java - BiMap with uniqueness along the set (key, value)?
问题描述
I've seen that BiMap
is for a bidirectional-map, that is link two set.
But does it exists a class that ensures unique-ness along with the set keys and values? (one-to-one relationship) With possibly a unique method get()
, that is theoretically possible with that. The keys and values have the same class.
Bonus: is BiMap.inverse()
complexity constant ?
解决方案
确保唯一性以及设置的键和值
键和值具有相同的类。
看来您需要不同的数据结构,而不是BiMap
. 您是否考虑过无向Graph
1或Network
2?
class Person { String name;}
final var john = new Person("John");
final var jane = new Person("Jane");
final MutableGraph<Person> graph = GraphBuilder.undirected().build();
graph.putEdge(john, jane);
Assertions.assertTrue(graph.hasEdgeConnecting(john, jane));
Assertions.assertTrue(graph.hasEdgeConnecting(jane, john));
Assertions.assertEquals(graph.adjacentNodes(jane), Set.of(john));
Assertions.assertEquals(graph.adjacentNodes(john), Set.of(jane));
推荐阅读
- swift - SwiftUI / Firestore“无法将'String'类型的值转换为预期的参数类型''
- amazon-web-services - 如何从 AWS Dynamodb Streams 触发特定的 AWS Lambda 版本
- python - Python urljoin 用于 html 表单 url
- sql - oracle sql join 与 listAgg ,使用 switch case
- python-3.x - Gitlab:Docker 中的 Docker?
- zip - 如何使用 cmd 行拆分和加入 zip 文件?
- keras - 为什么我的多标签文本分类 LSTM 表现不佳?
- javascript - TinyMCE - Wiris:无法初始化插件:tiny_mce_wiris 类型错误:M.cfg 未定义
- java - 具有 ResponseEntity 的 Spring Boot 控制器测试始终返回空响应
- javascript - 如何创建 react-chartjs 插件