我想要并行修改或克隆/转换预先排序的树项目列表中的项目。也就是列表遍历从列表中的随机项开始,表示子树遍历(深度,父指针,descendantSize和angleStart / angleEnd可用于径向视图)。
我的代码目前看起来像:
items = ((AbsModel<SunburstContainer, SunburstItem>)model).listIterator(pHitItemIndex);
items.next();
for (int i = pHitItemIndex + 1; i < endIndex && items.hasNext(); i++) {
final SunburstItem oldChild = items.next();
final SunburstItem newChild = new SunburstItem(oldChild);
final float newStartAngle =
(oldChild.getAngleStart() - oldRoot.getAngleStart()) * angleFactor;
LOGWRAPPER.debug("angleStart: " + newStartAngle);
newChild.setAngleStart(newStartAngle);
float newEndAngle =
(oldChild.getAngleEnd() - oldChild.getAngleStart()) * angleFactor
+ newChild.getAngleStart();
LOGWRAPPER.debug("angleEnd: " + newEndAngle);
if (newEndAngle > PConstants.TWO_PI) {
newEndAngle = PConstants.TWO_PI;
}
newChild.setAngleEnd(newEndAngle);
newChild.setAngleCenter(newChild.getAngleStart()
+ ((newChild.getAngleEnd() - newChild.getAngleStart()) / 2f));
newChild.setIndexToParent(oldChild.getIndexToParent() - pHitItemIndex);
int newDepth = 0;
LOGWRAPPER.debug("child depth: " + oldChild.getDepth());
LOGWRAPPER
.debug("parent depth: " + model.getItem(oldChild.getIndexToParent()).getDepth());
final int parentDepth = model.getItem(oldChild.getIndexToParent()).getDepth();
if ((parentDepth + 1) != oldChild.getDepth()) {
newDepth = oldDepthMax + 2;
} else {
newDepth = newItems.get(newChild.getIndexToParent()).getDepth() + 1;
}
if (newDepth > depthMax) {
depthMax = newDepth;
}
LOGWRAPPER.debug("newDepth: " + newDepth);
newChild.setDepth(newDepth);
newChild.update(mMappingMode, mBuffer);
newItems.add(newChild);
}
我想简单地将(子)列表(即[pHitItemIndex + 1,endIndex])划分为不同的部分,并将Callables提交给ExecutorService。目前整个算法是在提交给ExecutorService的Callable中执行的,但我想我也可以简单地将partition / Callables提交给同一个ExecutorService。我想知道我是否会获得使用actor的优势,例如使用Akka或使用ForkJoin框架。
答案 0 :(得分:0)
听起来像Scala中的并行集合可以提供帮助的问题。