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

Provide a way to coalesce the entries in a RangeMap #2665

Closed
dimo414 opened this issue Nov 30, 2016 · 4 comments
Closed

Provide a way to coalesce the entries in a RangeMap #2665

dimo414 opened this issue Nov 30, 2016 · 4 comments

Comments

@dimo414
Copy link
Contributor

dimo414 commented Nov 30, 2016

RangeMap doesn't coalesce connected ranges (by design), and it would be nice if there were a built-in way to coalesce connected ranges if they have the same value. For example:

{[0..1): 1, [1..2): 1, [2..3): 2}

Is roughly equivalent to:

{[0..2): 1, [2..3): 2}

And it can be both a time and space savings to be working with a smaller data structure. Particularly for a case such as a RangeMap built up from Range.singleton() keys a coalesced() operation could save a lot of resources.

@lowasser
Copy link
Contributor

Could you live with a RangeMaps.coalesced operation, that is, a one-off coalesce operation rather than doing it online?

@dimo414
Copy link
Contributor Author

dimo414 commented Nov 30, 2016

Definitely; I'd expect it to be a copy operation as a live view would eliminate the benefit of reducing the underlying number of ranges in use (and probably be much more complex to implement). ImmutableRangeMap.coalescedFrom(RangeMap) could also work.

cpovirk pushed a commit that referenced this issue Jan 4, 2017
@dimo414
Copy link
Contributor Author

dimo414 commented Jan 4, 2017

We opted to add a mutating .putCoalescing() operation rather than a copy or a view. Please let us know if you have a use case for which this isn't sufficient.

@perceptron8
Copy link
Contributor

@dimo414 I'd like to report "merging + coalescing" as a general use case, that .putCoalescing doesn't support at all. I think that .coalesced() (or similarly named) method could work nicely with #6822, or at least as a way to "clean-up" after series of RangeMap.merge calls (see #3641 for details if you like).

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

3 participants