Java 集合的多个索引 - 最基本的解决方案? [英] Multiple indexes for a Java Collection - most basic solution?

查看:18
本文介绍了Java 集合的多个索引 - 最基本的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在 Java 集合上创建多个索引的最基本的解决方案.

I'm looking for the most basic solution to create multiple indexes on a Java Collection.

所需功能:

  • 删除值后,必须删除与该值关联的所有索引条目.
  • 索引查找必须比线性搜索更快(至少与 TreeMap 一样快).

附带条件:

  • 不依赖大型(如 Lucene)库.没有不常见或未经充分测试的库.没有数据库.
  • 像 Apache Commons Collections 之类的库就可以了.
  • 更好,如果它可以单独使用 JavaSE (6.0).
  • 没有自行实施的解决方案(感谢提出这一建议的答案 - 为了完整起见,将它们放在此处很好,但我已经有了一个与 Jay 非常相似的解决方案)每当有几个人们发现,他们实现了相同的东西,这应该是某个公共库的一部分.
  • No dependencies on large (like Lucene) libraries. No uncommon or not well tested libraries. No database.
  • A library like Apache Commons Collections etc. would be ok.
  • Even better, if it works with JavaSE (6.0) alone.
  • No self-implemented solution (thanks for the answers suggesting this - it's good to have them here for completeness, but I already have a solution very similar to Jay's) Whenever several people find out, that they implemented the same thing, this should be part of some common library.

当然,我可以自己编写一个管理多个 Map 的类(这并不难,但感觉就像重新发明轮子).所以我想知道,是否可以在没有的情况下完成 - 同时仍然获得类似于使用单个索引的 java.util.Map 的简单用法.

Of course, I could write a class that manages multiple Maps myself (that's not hard, but it feels like reinventing the wheel). So I'd like to know, if it can be done without - while still getting a simple usage similar to using a single indexed java.util.Map.

谢谢,克里斯

看起来好像我们什么也没找到.我喜欢你所有的答案 - 自己开发的版本,类似数据库的库的链接.

It looks very much as if we haven't found anything. I like all your answers - the self developed versions, the links to database-like libraries.

这就是我真正想要的:在 (a) Apache Commons Collections 或 (b) Google Collections/Guava 中拥有功能.或者也许是一个非常好的选择.

Here's what I really want: To have the functionality in (a) Apache Commons Collections or (b) in Google Collections/Guava. Or maybe a very good alternative.

其他人是否也错过了这些库中的此功能?他们确实提供了各种各样的东西,比如 MultiMaps、MulitKeyMaps、BidiMaps ……我觉得它很适合这些库——它可以被称为 MultiIndexMap.你怎么看?

Do other people miss this functionality in these libraries, too? They do provide all sorts of things like MultiMaps, MulitKeyMaps, BidiMaps, ... I feel, it would fit in those libraries nicely - it could be called MultiIndexMap. What do you think?

推荐答案

每个索引基本上都是一个单独的Map.您可以(并且可能应该)将其抽象为一个为您管理搜索、索引、更新和删除的类.相当普遍地做到这一点并不难.但是不,虽然它可以很容易地从 Java Collections 类构建,但没有标准的开箱即用类.

Each index will basically be a separate Map. You can (and probably should) abstract this behind a class that manages the searches, indexing, updates and removals for you. It wouldn't be hard to do this fairly generically. But no, there's no standard out of the box class for this although it can easily be built from the Java Collections classes.

这篇关于Java 集合的多个索引 - 最基本的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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