Java相当于std :: deque [英] Java equivalent of std::deque

查看:247
本文介绍了Java相当于std :: deque的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个来自C ++ / STL的相对较新的Java程序员,我正在寻找一个具有这些特征的类(根据我的理解,它是C ++ std :: deque):

I'm a relatively new Java programmer coming from C++/STL, and am looking for a class with these characteristics (which the C++ std::deque has, as I understand it):


  1. O(1)在开始/结束时执行插入/删除

  2. li>
  3. 是可扩展集合(不需要固定大小边界)

这个?我找到了Java 1.6 [ArrayDeque]类,它有insert / remove和growable特性,但似乎没有lookup-by-index,除非你调用toArray(),它不会是O(1)。

Is there a Java equivalent to this? I found the Java 1.6 [ArrayDeque] class which has the insert/removal and growable characteristics, but don't seem to have lookup-by-index unless you call toArray() which would not be O(1).

推荐答案

Java的基本集合有一个带有get(int idx)方法的ArrayDeque。

Primitive Collections for Java has an ArrayDeque with a get(int idx) method.

http://sourceforge.net/projects/pcj

我不能保证这个项目的质量。

I can't vouch for the quality of this project though.

另一种方法是获取JDK ArrayDeque源并添加get idx)方法。应该比较容易。

An alternative would be to get the JDK ArrayDeque source and add the get(int idx) method yourself. Should be relatively easy.

编辑:如果你打算以高度多线程的方式使用deque,我会去修补JDK的ArrayDeque路由。此实现已经过彻底测试,并在新的java.util.concurrent ForkJoin框架中使用。

If you intend to use the deque in a highly multi-threaded manner, I would go the "patch the JDK's ArrayDeque" route. This implementation has been tested thoroughly and is used in the new java.util.concurrent ForkJoin framework.

这篇关于Java相当于std :: deque的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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