Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
lscsoft
ligo-segments
Commits
b8e57142
Commit
b8e57142
authored
Oct 05, 2018
by
Kipp Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use __all__ to control exported symbols
parent
88e76ec2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
13 deletions
+23
-13
ligo/segments.py
ligo/segments.py
+23
-13
No files found.
ligo/segments.py
View file @
b8e57142
...
...
@@ -42,15 +42,25 @@ glue.segmentsUtils
"""
from
bisect
import
bisect_left
as
_bisect_left
from
bisect
import
bisect_right
as
_bisect_right
from
copy
import
copy
as
_
shallowcopy
from
bisect
import
bisect_left
from
bisect
import
bisect_right
from
copy
import
copy
as
shallowcopy
__author__
=
"Kipp Cannon <kipp.cannon@ligo.org>"
__version__
=
'1.0.0'
__all__
=
[
"infinity"
,
"PosInfinity"
,
"NegInfinity"
,
"segment"
,
"segmentlist"
,
"segmentlistdict"
]
#
# =============================================================================
#
...
...
@@ -550,7 +560,7 @@ class segmentlist(list):
"""
if
isinstance
(
item
,
self
.
__class__
):
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
]))
# supplementary accessors
...
...
@@ -624,7 +634,7 @@ class segmentlist(list):
return
self
i
=
0
for
seg
in
other
:
i
=
j
=
_
bisect_right
(
self
,
seg
,
i
)
i
=
j
=
bisect_right
(
self
,
seg
,
i
)
lo
,
hi
=
seg
if
i
and
self
[
i
-
1
][
1
]
>=
lo
:
i
-=
1
...
...
@@ -736,7 +746,7 @@ class segmentlist(list):
other is not the null set, otherwise returns False. The
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
]))
def
intersects
(
self
,
other
):
...
...
@@ -986,7 +996,7 @@ class segmentlistdict(dict):
keys
=
self
new
=
self
.
__class__
()
for
key
in
keys
:
new
[
key
]
=
_
shallowcopy
(
self
[
key
])
new
[
key
]
=
shallowcopy
(
self
[
key
])
dict
.
__setitem__
(
new
.
offsets
,
key
,
self
.
offsets
[
key
])
return
new
...
...
@@ -1096,7 +1106,7 @@ class segmentlistdict(dict):
if
key
in
self
:
self
[
key
]
|=
value
else
:
self
[
key
]
=
_
shallowcopy
(
value
)
self
[
key
]
=
shallowcopy
(
value
)
return
self
def
__or__
(
self
,
other
):
...
...
@@ -1121,7 +1131,7 @@ class segmentlistdict(dict):
if
key
in
self
:
self
[
key
]
^=
value
else
:
self
[
key
]
=
_
shallowcopy
(
value
)
self
[
key
]
=
shallowcopy
(
value
)
return
self
def
__xor__
(
self
,
other
):
...
...
@@ -1201,7 +1211,7 @@ class segmentlistdict(dict):
"""
for
key
,
value
in
other
.
items
():
if
key
not
in
self
:
self
[
key
]
=
_
shallowcopy
(
value
)
self
[
key
]
=
shallowcopy
(
value
)
else
:
self
[
key
].
extend
(
value
)
...
...
@@ -1240,7 +1250,7 @@ class segmentlistdict(dict):
new
=
self
.
__class__
()
intersection
=
self
.
intersection
(
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
])
return
new
...
...
@@ -1281,7 +1291,7 @@ class segmentlistdict(dict):
keys
=
set
(
keys
)
if
not
keys
:
return
segmentlist
()
seglist
=
_
shallowcopy
(
self
[
keys
.
pop
()])
seglist
=
shallowcopy
(
self
[
keys
.
pop
()])
for
key
in
keys
:
seglist
&=
self
[
key
]
return
seglist
...
...
@@ -1294,7 +1304,7 @@ class segmentlistdict(dict):
keys
=
set
(
keys
)
if
not
keys
:
return
segmentlist
()
seglist
=
_
shallowcopy
(
self
[
keys
.
pop
()])
seglist
=
shallowcopy
(
self
[
keys
.
pop
()])
for
key
in
keys
:
seglist
|=
self
[
key
]
return
seglist
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment