Balzanka / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Add RangeMap.size() method #1371

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As of version 15.0-SNAPSHOT, RangeMap does not have an explicit size() method

http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect
/RangeMap.html

The size can be queried through the Map view

int size = rangeMap.asMapOfRanges().size();

In my use case I want the sizes of sub ranges, so I would be viewing a view 
just to get the size

int size = rangeMap.subRangeMap(Range.closed(1, 42)).asMapOfRanges().size();

I assume that views are implemented efficiently but it would be nice to have 
size() directly on RangeMap.

Original issue reported on code.google.com by heue...@gmail.com on 18 Apr 2013 at 5:14

GoogleCodeExporter commented 9 years ago
I can understand that desire, but I'm somewhat concerned that that's easily 
confused with some measure of the "size of the ranges," e.g. that a RangeMap 
with a Range from 1 to 42 would have size 42, or something along those lines.  
Thoughts?

Original comment by wasserman.louis on 18 Apr 2013 at 5:31

GoogleCodeExporter commented 9 years ago
> [..] I'm somewhat concerned that that's easily confused with some measure of 
the "size of the ranges," e.g. that a RangeMap with a Range from 1 to 42 would 
have size 42, or something along those lines.  Thoughts?

When I read the title of this ticket, i.e. before I clicked on it, that was the 
first semantics for RangeMap#size() I came up with. Admittedly I haven't yet 
used RangeMap extensively, but I guess it does show that your concern is 
warranted.

Original comment by stephan...@gmail.com on 18 Apr 2013 at 7:06

GoogleCodeExporter commented 9 years ago
Thank you for the quick replies.

As I work more with RangeMap (in the context of storing features on genomic 
sequences, see e.g. http://www.sequenceontology.org/gff3.shtml), I am finding 
that most of my interaction will be through the asMapOfRanges() view.

I also think the concern about confusion with size() is valid; I would be ok 
marking this issue as WontFix, perhaps after being left a while for further 
comment.

Original comment by heue...@gmail.com on 18 Apr 2013 at 7:12

GoogleCodeExporter commented 9 years ago
would using a DiscreteDomain be to obfuscating?

{
   [0,5)=A
   [10,14)=B
   [40,42)=C
}

size = rangeMap.size(integers());

// size = 5 + 4 + 2 = 11

Original comment by jysjys1...@gmail.com on 20 Apr 2013 at 5:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Also, to this effect, I suppose: is it practical to have a view of the 
comparable items to the associated values? I suppose it would be akin to a 
ContiguousSet.

i.e.

Range<Integer> range;
Object o;
Map.Entry<Range<Integer>, Object> entry;
DiscreteDomain<Integer> domain;

...

ContiguousMap.create(domain, range, o);
ContiguousMap.create(domain, entry);

...

RangeMap<Integer, Object> rangeMap;
Map<Range<Integer>, Object> mapOfRanges;

...

PiecewiseMap.create(domain, rangeMap);
PiecewiseMap.create(domain, mapOfRanges);

Original comment by jysjys1...@gmail.com on 23 Apr 2013 at 5:10

GoogleCodeExporter commented 9 years ago
If size() is not added to the interface is it possible to get isEmpty() 
analogous to RangeSet#isEmpty()?

Original comment by markus.s...@gmail.com on 2 Sep 2013 at 6:22

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:18