Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove overlaps #134

Open
mbhall88 opened this issue Jan 24, 2024 · 1 comment
Open

Remove overlaps #134

mbhall88 opened this issue Jan 24, 2024 · 1 comment

Comments

@mbhall88
Copy link

mbhall88 commented Jan 24, 2024

I love this library. I use it A LOT!

One function I would love to have on an IntervalTree is remove_overlaps. This would remove anyway interval within the tree that overlaps with another.

My current work around is effectively this

remove = []
for iv in tree:
    overlaps = list(tree.overlap(iv))
    if len(overlaps) > 1:
        remove.extend(overlaps)

for iv in remove:
    tree.remove(iv)
@snewell92
Copy link

I would suggest splitting this functionality in two. I have a use case right now where I need to find all intervals in a given tree that overlap, which the first part of the above code does (which is what i will write), so splitting this up would yield an API like (pls excuse the quick psuedo code):

def get_all_overlaps(self):
    for interval in self:
        # TODO this will likely yield duplicate sets, so further refinement is needed
        yield tree.overlap(interval)

# suggest 'pruning' as the action to the tree, but remove still fine
def prune_all_overlaps(self):
    removed = []

    for overlaps in self.get_all_overlaps():
        for interval in overlaps:
            removed.append(interval)
            self.remove(interval)

    return removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants