Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
4b8d55f9
Commit
4b8d55f9
authored
Dec 04, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
weightedIntersection must work even when merging is impossible (e.g. two sets).
parent
990678ff
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
BTrees/_base.py
BTrees/_base.py
+12
-5
BTrees/tests/test__base.py
BTrees/tests/test__base.py
+16
-0
No files found.
BTrees/_base.py
View file @
4b8d55f9
...
...
@@ -1286,7 +1286,6 @@ def weightedIntersection(set_type, o1, o2, w1=1, w2=1):
MERGE_DEFAULT
=
getattr
(
o1
,
'MERGE_DEFAULT'
,
None
)
i1
=
_SetIteration
(
o1
,
True
,
MERGE_DEFAULT
)
i2
=
_SetIteration
(
o2
,
True
,
MERGE_DEFAULT
)
result
=
o1
.
_mapping_type
()
MERGE
=
getattr
(
o1
,
'MERGE'
,
None
)
if
MERGE
is
None
and
i1
.
useValues
and
i2
.
useValues
:
raise
TypeError
(
"invalid set operation"
)
...
...
@@ -1300,15 +1299,23 @@ def weightedIntersection(set_type, o1, o2, w1=1, w2=1):
raise
TypeError
(
"invalid set operation"
)
else
:
raise
TypeError
(
"invalid set operation"
)
_merging
=
i1
.
useValues
or
i2
.
useValues
if
_merging
:
result
=
o1
.
_mapping_type
()
def
copy
(
i
,
w
):
result
.
_keys
.
append
(
i
.
key
)
result
.
_values
.
append
(
MERGE_WEIGHT
(
i
.
value
,
w
))
else
:
result
=
o1
.
_set_type
()
def
copy
(
i
,
w
):
result
.
_keys
.
append
(
i
.
key
)
while
i1
.
active
and
i2
.
active
:
cmp_
=
cmp
(
i1
.
key
,
i2
.
key
)
if
cmp_
<
0
:
i1
.
advance
()
elif
cmp_
==
0
:
result
.
_keys
.
append
(
i1
.
key
)
if
_merging
:
result
.
_values
.
append
(
MERGE
(
i1
.
value
,
w1
,
i2
.
value
,
w2
))
i1
.
advance
()
i2
.
advance
()
...
...
BTrees/tests/test__base.py
View file @
4b8d55f9
...
...
@@ -2653,6 +2653,14 @@ class Test_weightedUnion(unittest.TestCase, _SetObBase):
self
.
assertEqual
(
result
[
'd'
],
33
)
self
.
assertEqual
(
result
[
'e'
],
11
)
def
test_w_lhs_Set_rhs_Set
(
self
):
from
BTrees.IIBTree
import
IISetPy
lhs
=
IISetPy
([
1
,
2
,
3
])
rhs
=
IISetPy
([
1
,
4
])
weight
,
result
=
self
.
_callFUT
(
lhs
.
__class__
,
lhs
,
rhs
)
self
.
assertEqual
(
weight
,
1
)
self
.
assertEqual
(
list
(
result
),
[
1
,
2
,
3
,
4
])
class
Test_weightedIntersection
(
unittest
.
TestCase
,
_SetObBase
):
...
...
@@ -2695,6 +2703,14 @@ class Test_weightedIntersection(unittest.TestCase, _SetObBase):
self
.
assertEqual
(
list
(
result
),
[
'a'
])
self
.
assertEqual
(
result
[
'a'
],
23
)
def
test_w_lhs_Set_rhs_Set
(
self
):
from
BTrees.IIBTree
import
IISetPy
lhs
=
IISetPy
([
1
,
2
,
3
])
rhs
=
IISetPy
([
1
,
4
])
weight
,
result
=
self
.
_callFUT
(
lhs
.
__class__
,
lhs
,
rhs
)
self
.
assertEqual
(
weight
,
2
)
self
.
assertEqual
(
list
(
result
),
[
1
])
class
Test_multiunion
(
unittest
.
TestCase
,
_SetObBase
):
...
...
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