Commit b8e57142 authored by Kipp Cannon's avatar Kipp Cannon
Browse files

use __all__ to control exported symbols

parent 88e76ec2
...@@ -42,15 +42,25 @@ glue.segmentsUtils ...@@ -42,15 +42,25 @@ glue.segmentsUtils
""" """
from bisect import bisect_left as _bisect_left from bisect import bisect_left
from bisect import bisect_right as _bisect_right from bisect import bisect_right
from copy import copy as _shallowcopy from copy import copy as shallowcopy
__author__ = "Kipp Cannon <kipp.cannon@ligo.org>" __author__ = "Kipp Cannon <kipp.cannon@ligo.org>"
__version__ = '1.0.0' __version__ = '1.0.0'
__all__ = [
"infinity",
"PosInfinity",
"NegInfinity",
"segment",
"segmentlist",
"segmentlistdict"
]
# #
# ============================================================================= # =============================================================================
# #
...@@ -550,7 +560,7 @@ class segmentlist(list): ...@@ -550,7 +560,7 @@ class segmentlist(list):
""" """
if isinstance(item, self.__class__): if isinstance(item, self.__class__):
return all(seg in self for seg in item) return all(seg in self for seg in item)
i = _bisect_left(self, item) i = bisect_left(self, item)
return ((i != 0) and (item in self[i-1])) or ((i != len(self)) and (item in self[i])) return ((i != 0) and (item in self[i-1])) or ((i != len(self)) and (item in self[i]))
# supplementary accessors # supplementary accessors
...@@ -624,7 +634,7 @@ class segmentlist(list): ...@@ -624,7 +634,7 @@ class segmentlist(list):
return self return self
i = 0 i = 0
for seg in other: for seg in other:
i = j = _bisect_right(self, seg, i) i = j = bisect_right(self, seg, i)
lo, hi = seg lo, hi = seg
if i and self[i - 1][1] >= lo: if i and self[i - 1][1] >= lo:
i -= 1 i -= 1
...@@ -736,7 +746,7 @@ class segmentlist(list): ...@@ -736,7 +746,7 @@ class segmentlist(list):
other is not the null set, otherwise returns False. The other is not the null set, otherwise returns False. The
algorithm is O(log n). Requires the list to be coalesced. algorithm is O(log n). Requires the list to be coalesced.
""" """
i = _bisect_left(self, other) i = bisect_left(self, other)
return ((i != 0) and (other[0] < self[i-1][1])) or ((i != len(self)) and (other[1] > self[i][0])) return ((i != 0) and (other[0] < self[i-1][1])) or ((i != len(self)) and (other[1] > self[i][0]))
def intersects(self, other): def intersects(self, other):
...@@ -986,7 +996,7 @@ class segmentlistdict(dict): ...@@ -986,7 +996,7 @@ class segmentlistdict(dict):
keys = self keys = self
new = self.__class__() new = self.__class__()
for key in keys: for key in keys:
new[key] = _shallowcopy(self[key]) new[key] = shallowcopy(self[key])
dict.__setitem__(new.offsets, key, self.offsets[key]) dict.__setitem__(new.offsets, key, self.offsets[key])
return new return new
...@@ -1096,7 +1106,7 @@ class segmentlistdict(dict): ...@@ -1096,7 +1106,7 @@ class segmentlistdict(dict):
if key in self: if key in self:
self[key] |= value self[key] |= value
else: else:
self[key] = _shallowcopy(value) self[key] = shallowcopy(value)
return self return self
def __or__(self, other): def __or__(self, other):
...@@ -1121,7 +1131,7 @@ class segmentlistdict(dict): ...@@ -1121,7 +1131,7 @@ class segmentlistdict(dict):
if key in self: if key in self:
self[key] ^= value self[key] ^= value
else: else:
self[key] = _shallowcopy(value) self[key] = shallowcopy(value)
return self return self
def __xor__(self, other): def __xor__(self, other):
...@@ -1201,7 +1211,7 @@ class segmentlistdict(dict): ...@@ -1201,7 +1211,7 @@ class segmentlistdict(dict):
""" """
for key, value in other.items(): for key, value in other.items():
if key not in self: if key not in self:
self[key] = _shallowcopy(value) self[key] = shallowcopy(value)
else: else:
self[key].extend(value) self[key].extend(value)
...@@ -1240,7 +1250,7 @@ class segmentlistdict(dict): ...@@ -1240,7 +1250,7 @@ class segmentlistdict(dict):
new = self.__class__() new = self.__class__()
intersection = self.intersection(keys) intersection = self.intersection(keys)
for key in keys: for key in keys:
dict.__setitem__(new, key, _shallowcopy(intersection)) dict.__setitem__(new, key, shallowcopy(intersection))
dict.__setitem__(new.offsets, key, self.offsets[key]) dict.__setitem__(new.offsets, key, self.offsets[key])
return new return new
...@@ -1281,7 +1291,7 @@ class segmentlistdict(dict): ...@@ -1281,7 +1291,7 @@ class segmentlistdict(dict):
keys = set(keys) keys = set(keys)
if not keys: if not keys:
return segmentlist() return segmentlist()
seglist = _shallowcopy(self[keys.pop()]) seglist = shallowcopy(self[keys.pop()])
for key in keys: for key in keys:
seglist &= self[key] seglist &= self[key]
return seglist return seglist
...@@ -1294,7 +1304,7 @@ class segmentlistdict(dict): ...@@ -1294,7 +1304,7 @@ class segmentlistdict(dict):
keys = set(keys) keys = set(keys)
if not keys: if not keys:
return segmentlist() return segmentlist()
seglist = _shallowcopy(self[keys.pop()]) seglist = shallowcopy(self[keys.pop()])
for key in keys: for key in keys:
seglist |= self[key] seglist |= self[key]
return seglist return seglist
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment