简体   繁体   English

IntervalTree DeleteNode Java实现

[英]IntervalTree DeleteNode Java Implementation

I need an IntervalTree or RangeTree implementation in Java, and am having trouble finding one with working deletion support. 我需要在Java中使用IntervalTree或RangeTree,并且无法找到具有工作删除支持的实现。

There's a built-in one at sun.jvm.hotspot.utilities.IntervalTree , but the deleteNode method in the RBTree superclass states: sun.jvm.hotspot.utilities.IntervalTree中有一个内置的,但RBTree超类中的deleteNode方法指出:

/**
 * FIXME: this does not work properly yet for augmented red-black
 * trees since it doesn't update nodes. Need to figure out exactly
 * from which points we need to propagate updates upwards.
 */

Trying to delete nodes from a tree ends up throwing the exception: 尝试从树中删除节点最终会抛出异常:

Node's max endpoint was not updated properly 节点的最大端点未正确更新

How difficult would it be to properly implement delete functionality in a subclass of the sun.jvm.hotspot.utilities.IntervalTree? 在sun.jvm.hotspot.utilities.IntervalTree的子类中正确实现delete功能有多难? Or is there another Interval Tree implementation which already implements this correctly? 或者是否有另一个Interval Tree实现已经正确实现了这个?

Currently I'm just wiping out the tree and re-populating it every time there's a deletion, which is far from ideal (note: setting DEBUGGING=false in the RBTree sped things up tremendously). 目前我只是在擦除树并在每次删除时重新填充它,这远非理想(注意:在RBTree中设置DEBUGGING = false会大大加快速度)。

I ended up modifying the sun.jvm.hotspot.utilities.IntervalTree to maintain a Set of deleted nodes. 我最终修改了sun.jvm.hotspot.utilities.IntervalTree以维护一组已删除的节点。 When doing a search, I exclude any items in this set. 在进行搜索时,我会排除此集合中的所有项目。 Not ideal, but this was a lot easier than getting "real" deletion working. 不理想,但这比“真正的”删除工作容易得多。 Once the deleted set gets too large, I rebuild the tree. 一旦删除的集合变得太大,我就重建了树。

This project has a RangeTree implementation that might be of more use to you. 该项目有一个RangeTree实现,可能对您有用。 The sun packages might be ok for quick-and-dirty use, but I would not recommend building anything important relying on them. 太阳包可能适合快速和肮脏的使用,但我不建议建立任何重要的依赖它们。 Sun may not keep them stable. 太阳可能无法保持稳定。

there's ac# implementation based on an augmented AVL tree @ http://code.google.com/p/intervaltree/ . 有一个基于增强AVL树的ac#实现@ http://code.google.com/p/intervaltree/ translation to java shouldn't be too difficult. 翻译成java应该不会太难。

I found an open-source implementation with deletion, but it neeeds some effort to make it fully functional. 我找到了一个带删除的开源实现,但需要付出一些努力才能使其完全正常运行。

It's a module of larger open-source project Gephi , but here are the sources and javadoc . 它是较大的开源项目Gephi的一个模块,但这里有源 代码javadoc If you want a jar you can install the Gephi, and it's in: 如果你想要一个罐子,你可以安装Gephi,它在:

/gephi/modules/org-gephi-data-attributes-api.jar

The delete method there, removes all intervals overlapping with the input interval (instead of just the input one). 删除方法,删除与输入间隔重叠的所有间隔(而不仅仅是输入间隔)。 However I found in the soruces that there are private methods that remove a specific node (which stores one interval). 但是我在soruces中发现有私有方法删除特定节点(存储一个间隔)。 Also the private search methods return nodes. 私有搜索方法也返回节点。

So I think with some little effort it's possible to refactor the code and have this - 'delete specific interval' feature. 所以我认为通过一些小小的努力,可以重构代码并具有 - “删除特定间隔”功能。 The fastest and most dirty way would be to just make the private methods/Node class public. 最快和最脏的方法是将私有方法/ Node类公开。 But since it's an open source project, maybe it could evolve in future into some good standard implementation of interval tree. 但由于它是一个开源项目,它可能会在未来发展成为区间树的一些良好的标准实现。

I don't know your exact requirements but a non-static Segment Tree might work for you. 我不知道您的确切要求,但非静态段树可能适合您。 If so, have a look at Layout Management SW , specifically the SegmentTree package . 如果是这样,请查看布局管理SW ,特别是SegmentTree包 It has the remove feature you need. 它具有您需要的删除功能。

If you decide to roll your own, might I suggest open sourcing it? 如果您决定推销自己,我可以建议开源吗? I'm surprised there isn't an open and easy Interval Tree available already. 我很惊讶没有一个开放简单的Interval Tree可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM