Loading tools/releasetools/rangelib.py +11 −4 Original line number Original line Diff line number Diff line Loading @@ -24,12 +24,13 @@ class RangeSet(object): lots of runs.""" lots of runs.""" def __init__(self, data=None): def __init__(self, data=None): # TODO(tbao): monotonic is broken when passing in a tuple. self.monotonic = False self.monotonic = False if isinstance(data, str): if isinstance(data, str): self._parse_internal(data) self._parse_internal(data) elif data: elif data: assert len(data) % 2 == 0 self.data = tuple(self._remove_pairs(data)) self.data = tuple(self._remove_pairs(data)) self.monotonic = all(x < y for x, y in zip(self.data, self.data[1:])) else: else: self.data = () self.data = () Loading @@ -39,8 +40,10 @@ class RangeSet(object): def __eq__(self, other): def __eq__(self, other): return self.data == other.data return self.data == other.data def __ne__(self, other): def __ne__(self, other): return self.data != other.data return self.data != other.data def __nonzero__(self): def __nonzero__(self): return bool(self.data) return bool(self.data) Loading Loading @@ -74,9 +77,9 @@ class RangeSet(object): monotonic = True monotonic = True for p in text.split(): for p in text.split(): if "-" in p: if "-" in p: s, e = p.split("-") s, e = (int(x) for x in p.split("-")) data.append(int(s)) data.append(s) data.append(int(e)+1) data.append(e+1) if last <= s <= e: if last <= s <= e: last = e last = e else: else: Loading @@ -95,6 +98,9 @@ class RangeSet(object): @staticmethod @staticmethod def _remove_pairs(source): def _remove_pairs(source): """Remove consecutive duplicate items to simplify the result. [1, 2, 2, 5, 5, 10] will become [1, 10].""" last = None last = None for i in source: for i in source: if i == last: if i == last: Loading @@ -117,6 +123,7 @@ class RangeSet(object): return " ".join(out) return " ".join(out) def to_string_raw(self): def to_string_raw(self): assert self.data return str(len(self.data)) + "," + ",".join(str(i) for i in self.data) return str(len(self.data)) + "," + ",".join(str(i) for i in self.data) def union(self, other): def union(self, other): Loading Loading
tools/releasetools/rangelib.py +11 −4 Original line number Original line Diff line number Diff line Loading @@ -24,12 +24,13 @@ class RangeSet(object): lots of runs.""" lots of runs.""" def __init__(self, data=None): def __init__(self, data=None): # TODO(tbao): monotonic is broken when passing in a tuple. self.monotonic = False self.monotonic = False if isinstance(data, str): if isinstance(data, str): self._parse_internal(data) self._parse_internal(data) elif data: elif data: assert len(data) % 2 == 0 self.data = tuple(self._remove_pairs(data)) self.data = tuple(self._remove_pairs(data)) self.monotonic = all(x < y for x, y in zip(self.data, self.data[1:])) else: else: self.data = () self.data = () Loading @@ -39,8 +40,10 @@ class RangeSet(object): def __eq__(self, other): def __eq__(self, other): return self.data == other.data return self.data == other.data def __ne__(self, other): def __ne__(self, other): return self.data != other.data return self.data != other.data def __nonzero__(self): def __nonzero__(self): return bool(self.data) return bool(self.data) Loading Loading @@ -74,9 +77,9 @@ class RangeSet(object): monotonic = True monotonic = True for p in text.split(): for p in text.split(): if "-" in p: if "-" in p: s, e = p.split("-") s, e = (int(x) for x in p.split("-")) data.append(int(s)) data.append(s) data.append(int(e)+1) data.append(e+1) if last <= s <= e: if last <= s <= e: last = e last = e else: else: Loading @@ -95,6 +98,9 @@ class RangeSet(object): @staticmethod @staticmethod def _remove_pairs(source): def _remove_pairs(source): """Remove consecutive duplicate items to simplify the result. [1, 2, 2, 5, 5, 10] will become [1, 10].""" last = None last = None for i in source: for i in source: if i == last: if i == last: Loading @@ -117,6 +123,7 @@ class RangeSet(object): return " ".join(out) return " ".join(out) def to_string_raw(self): def to_string_raw(self): assert self.data return str(len(self.data)) + "," + ",".join(str(i) for i in self.data) return str(len(self.data)) + "," + ",".join(str(i) for i in self.data) def union(self, other): def union(self, other): Loading