IntervalTree DeleteNode Java Implementation

余生长醉 提交于 2019-12-03 03:22:52

I ended up modifying the sun.jvm.hotspot.utilities.IntervalTree to maintain a Set of deleted nodes. 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. 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.

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. 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.

there's a c# implementation based on an augmented AVL tree @ http://code.google.com/p/intervaltree/ . translation to java shouldn't be too difficult.

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. If you want a jar you can install the Gephi, and it's in:

/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). 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. But since it's an open source project, maybe it could evolve in future into some good standard implementation of interval tree.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!