Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
84f943c5
Commit
84f943c5
authored
Jun 25, 2002
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Repaired more of the weightedIntersection and weightedUnion docs. I'm
not sure it's telling the full truth yet.
parent
f6513a88
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
17 deletions
+34
-17
src/BTrees/Interfaces.py
src/BTrees/Interfaces.py
+28
-13
src/BTrees/tests/testSetOps.py
src/BTrees/tests/testSetOps.py
+6
-4
No files found.
src/BTrees/Interfaces.py
View file @
84f943c5
...
...
@@ -286,7 +286,7 @@ class IIMerge(IMerge):
"""
def
weightedUnion
(
c1
,
c2
,
weight1
=
1
,
weight2
=
1
):
"""Compute the weighted
U
nion of c1 and c2.
"""Compute the weighted
u
nion of c1 and c2.
If c1 and c2 are None, the output is (0, None).
...
...
@@ -294,18 +294,28 @@ class IIMerge(IMerge):
If c1 is not None and c2 is None, the output is (weight1, c1).
If c1 and c2 are not None and not both sets, the output is 1
and a Bucket such that the output values are::
Else, and hereafter, c1 is not None and c2 is not None.
If c1 and c2 are both sets, the output is the sum of the weights
and the (unweighted) union of the sets.
Else the output is 1 and a Bucket whose keys are the union of c1 and
c2's keys, and whose values are::
v1*weight1 + v2*weight2
where:
v1 is 0 if the key was not in c1. Otherwise, v1 is 1, if
c1 is a set, or the value from c1.
v1 is 0 if the key is not in c1
1 if the key is in c1 and c1 is a set
c1[key] if the key is in c1 and c1 is a mapping
v2 is 0 if the key was not in c2. Otherwise, v2 is 2, if
c2 is a set, or the value from c2.
v2 is 0 if the key is not in c2
1 if the key is in c2 and c2 is a set
c2[key] if the key is in c2 and c2 is a mapping
XXX All of the above is wrong if either weight is negative. I think
XXX that's a bug in the implementation and will fix it.
Note that c1 and c2 must be collections.
...
...
@@ -320,21 +330,26 @@ class IIMerge(IMerge):
If c1 is not None and c2 is None, the output is (weight1, c1).
Else, and hereafter, c1 is not None and c2 is not None.
If c1 and c2 are both sets, the output is the sum of the weights
and the (unweighted) intersection of the sets.
If c1 and c2 are not None and not both sets, the output is 1
and a Bucket such that the output
values are::
Else the output is 1 and a Bucket whose keys are the intersection of
c1 and c2's keys, and whose
values are::
v1*weight1 + v2*weight2
where:
v1 is 0 if the key was not in c1. Otherwise, v1 is 1, if
c1 is a set, or the value from c1.
v1 is 1 if c1 is a set
c1[key] if c1 is a mapping
v2 is 1 if c2 is a set
c1[key] if c2 is a mapping
v2 is 0 if the key was not in c2. Otherwise, v2 is 2, if
c2 is a set, or the value from c2
.
XXX All of the above is wrong if either weight is negative. I think
XXX that's a bug in the implementation and will fix it
.
Note that c1 and c2 must be collections.
"""
...
...
src/BTrees/tests/testSetOps.py
View file @
84f943c5
...
...
@@ -19,10 +19,6 @@ from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from
BTrees.IIBTree
import
IIBTree
,
IIBucket
,
IISet
,
IITreeSet
from
BTrees.OIBTree
import
OIBTree
,
OIBucket
,
OISet
,
OITreeSet
# XXX TODO Needs more tests.
# This file was created when multiunion was added. The other set operations
# don't appear to be tested anywhere yet.
# Subclasses have to set up:
# builders - functions to build inputs, taking an optional keys arg
# intersection, union, difference - set to the type-correct versions
...
...
@@ -388,6 +384,12 @@ class TestWeightedOI(Weighted):
builders
=
OIBucket
,
OIBTree
,
itemsToSet
(
OISet
),
itemsToSet
(
OITreeSet
)
# 'thing' is a bucket, btree, set or treeset. Return true iff it's one of the
# latter two.
def
isaset
(
thing
):
return
not
hasattr
(
thing
,
'values'
)
def
test_suite
():
s
=
TestSuite
()
for
klass
in
(
TestIIMultiUnion
,
TestIOMultiUnion
,
...
...
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