Merge "releasetools: RangeSet.monotonic is not an optional attribute." am: acb3cecc46
am: c6b824ba96
Change-Id: I58685e0b462964078147c5bc906d52d11d74668c
This commit is contained in:
commit
93c09cb740
|
@ -191,8 +191,7 @@ class Transfer(object):
|
||||||
self.tgt_sha1 = tgt_sha1
|
self.tgt_sha1 = tgt_sha1
|
||||||
self.src_sha1 = src_sha1
|
self.src_sha1 = src_sha1
|
||||||
self.style = style
|
self.style = style
|
||||||
self.intact = (getattr(tgt_ranges, "monotonic", False) and
|
self.intact = tgt_ranges.monotonic and src_ranges.monotonic
|
||||||
getattr(src_ranges, "monotonic", False))
|
|
||||||
|
|
||||||
# We use OrderedDict rather than dict so that the output is repeatable;
|
# We use OrderedDict rather than dict so that the output is repeatable;
|
||||||
# otherwise it would depend on the hash values of the Transfer objects.
|
# otherwise it would depend on the hash values of the Transfer objects.
|
||||||
|
|
|
@ -13,15 +13,22 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import heapq
|
import heapq
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["RangeSet"]
|
__all__ = ["RangeSet"]
|
||||||
|
|
||||||
|
|
||||||
class RangeSet(object):
|
class RangeSet(object):
|
||||||
"""A RangeSet represents a set of nonoverlapping ranges on the
|
"""A RangeSet represents a set of non-overlapping ranges on integers.
|
||||||
integers (ie, a set of integers, but efficient when the set contains
|
|
||||||
lots of runs."""
|
Attributes:
|
||||||
|
monotonic: Whether the input has all its integers in increasing order.
|
||||||
|
extra: A dict that can be used by the caller, e.g. to store info that's
|
||||||
|
only meaningful to caller.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, data=None):
|
def __init__(self, data=None):
|
||||||
self.monotonic = False
|
self.monotonic = False
|
||||||
|
@ -63,16 +70,18 @@ class RangeSet(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse(cls, text):
|
def parse(cls, text):
|
||||||
"""Parse a text string consisting of a space-separated list of
|
"""Parses a text string into a RangeSet.
|
||||||
blocks and ranges, eg "10-20 30 35-40". Ranges are interpreted to
|
|
||||||
include both their ends (so the above example represents 18
|
|
||||||
individual blocks. Returns a RangeSet object.
|
|
||||||
|
|
||||||
If the input has all its blocks in increasing order, then returned
|
The input text string consists of a space-separated list of blocks and
|
||||||
RangeSet will have an extra attribute 'monotonic' that is set to
|
ranges, e.g. "10-20 30 35-40". Ranges are interpreted to include both their
|
||||||
True. For example the input "10-20 30" is monotonic, but the input
|
ends (so the above example represents 18 individual blocks). Returns a
|
||||||
"15-20 30 10-14" is not, even though they represent the same set
|
RangeSet object.
|
||||||
of blocks (and the two RangeSets will compare equal with ==).
|
|
||||||
|
If the input has all its blocks in increasing order, then the 'monotonic'
|
||||||
|
attribute of the returned RangeSet will be set to True. For example the
|
||||||
|
input "10-20 30" is monotonic, but the input "15-20 30 10-14" is not, even
|
||||||
|
though they represent the same set of blocks (and the two RangeSets will
|
||||||
|
compare equal with ==).
|
||||||
"""
|
"""
|
||||||
return cls(text)
|
return cls(text)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue