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
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
Nicolas Wavrant
ZODB
Commits
0ffa6aa9
Commit
0ffa6aa9
authored
May 08, 2011
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reindented.
parent
55ed9237
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
139 deletions
+139
-139
src/BTrees/MergeTemplate.c
src/BTrees/MergeTemplate.c
+23
-23
src/BTrees/SetOpTemplate.c
src/BTrees/SetOpTemplate.c
+116
-116
No files found.
src/BTrees/MergeTemplate.c
View file @
0ffa6aa9
...
...
@@ -10,27 +10,27 @@
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE
****************************************************************************/
****************************************************************************/
#define MERGETEMPLATE_C "$Id$\n"
/****************************************************************************
Set operations
****************************************************************************/
****************************************************************************/
static
int
merge_output
(
Bucket
*
r
,
SetIteration
*
i
,
int
mapping
)
{
if
(
r
->
len
>=
r
->
size
&&
Bucket_grow
(
r
,
-
1
,
!
mapping
)
<
0
)
return
-
1
;
COPY_KEY
(
r
->
keys
[
r
->
len
],
i
->
key
);
INCREF_KEY
(
r
->
keys
[
r
->
len
]);
if
(
mapping
)
{
COPY_VALUE
(
r
->
values
[
r
->
len
],
i
->
value
);
INCREF_VALUE
(
r
->
values
[
r
->
len
]);
}
r
->
len
++
;
return
0
;
if
(
r
->
len
>=
r
->
size
&&
Bucket_grow
(
r
,
-
1
,
!
mapping
)
<
0
)
return
-
1
;
COPY_KEY
(
r
->
keys
[
r
->
len
],
i
->
key
);
INCREF_KEY
(
r
->
keys
[
r
->
len
]);
if
(
mapping
)
{
COPY_VALUE
(
r
->
values
[
r
->
len
],
i
->
value
);
INCREF_VALUE
(
r
->
values
[
r
->
len
]);
}
r
->
len
++
;
return
0
;
}
/* The "reason" argument is a little integer giving "a reason" for the
...
...
@@ -45,7 +45,7 @@ merge_error(int p1, int p2, int p3, int reason)
UNLESS
(
r
=
Py_BuildValue
(
"iiii"
,
p1
,
p2
,
p3
,
reason
))
r
=
Py_None
;
if
(
ConflictError
==
NULL
)
{
ConflictError
=
PyExc_ValueError
;
Py_INCREF
(
ConflictError
);
Py_INCREF
(
ConflictError
);
}
PyErr_SetObject
(
ConflictError
,
r
);
if
(
r
!=
Py_None
)
...
...
@@ -101,28 +101,28 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
}
if
(
initSetIteration
(
&
i1
,
OBJECT
(
s1
),
1
)
<
0
)
goto
err
;
goto
err
;
if
(
initSetIteration
(
&
i2
,
OBJECT
(
s2
),
1
)
<
0
)
goto
err
;
goto
err
;
if
(
initSetIteration
(
&
i3
,
OBJECT
(
s3
),
1
)
<
0
)
goto
err
;
goto
err
;
mapping
=
i1
.
usesValue
|
i2
.
usesValue
|
i3
.
usesValue
;
set
=
!
mapping
;
if
(
mapping
)
r
=
(
Bucket
*
)
PyObject_CallObject
((
PyObject
*
)
&
BucketType
,
NULL
);
r
=
(
Bucket
*
)
PyObject_CallObject
((
PyObject
*
)
&
BucketType
,
NULL
);
else
r
=
(
Bucket
*
)
PyObject_CallObject
((
PyObject
*
)
&
SetType
,
NULL
);
r
=
(
Bucket
*
)
PyObject_CallObject
((
PyObject
*
)
&
SetType
,
NULL
);
if
(
r
==
NULL
)
goto
err
;
goto
err
;
if
(
i1
.
next
(
&
i1
)
<
0
)
goto
err
;
goto
err
;
if
(
i2
.
next
(
&
i2
)
<
0
)
goto
err
;
goto
err
;
if
(
i3
.
next
(
&
i3
)
<
0
)
goto
err
;
goto
err
;
/* Consult zodb/btrees/interfaces.py for the meaning of the last
* argument passed to merge_error().
...
...
@@ -233,7 +233,7 @@ bucket_merge(Bucket *s1, Bucket *s2, Bucket *s3)
}
else
{
/* 1<2 and 1<3: both deleted 1.key */
merge_error
(
i1
.
position
,
i2
.
position
,
i3
.
position
,
5
);
merge_error
(
i1
.
position
,
i2
.
position
,
i3
.
position
,
5
);
goto
err
;
}
}
...
...
src/BTrees/SetOpTemplate.c
View file @
0ffa6aa9
...
...
@@ -10,11 +10,11 @@
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE
****************************************************************************/
****************************************************************************/
/****************************************************************************
Set operations
****************************************************************************/
****************************************************************************/
#define SETOPTEMPLATE_C "$Id$\n"
...
...
@@ -22,15 +22,15 @@
static
int
nextKeyAsSet
(
SetIteration
*
i
)
{
if
(
i
->
position
>=
0
)
{
if
(
i
->
position
)
{
DECREF_KEY
(
i
->
key
);
i
->
position
=
-
1
;
}
else
i
->
position
=
1
;
if
(
i
->
position
>=
0
)
{
if
(
i
->
position
)
{
DECREF_KEY
(
i
->
key
);
i
->
position
=
-
1
;
}
return
0
;
else
i
->
position
=
1
;
}
return
0
;
}
#endif
...
...
@@ -145,11 +145,11 @@ initSetIteration(SetIteration *i, PyObject *s, int useValues)
static
int
copyRemaining
(
Bucket
*
r
,
SetIteration
*
i
,
int
merge
,
/* See comment # 42 */
/* See comment # 42 */
#ifdef MERGE
VALUE_TYPE
w
)
#else
int
w
)
int
w
)
#endif
{
while
(
i
->
position
>=
0
)
...
...
@@ -201,16 +201,16 @@ static PyObject *
set_operation
(
PyObject
*
s1
,
PyObject
*
s2
,
int
usevalues1
,
int
usevalues2
,
/* Comment # 42
/* Comment # 42
The following ifdef works around a template/type problem
The following ifdef works around a template/type problem
Weights are passed as integers. In particular, the weight passed by
difference is one. This works fine in the int value and float value
cases but makes no sense in the object value case. In the object
value case, we don't do merging, so we don't use the weights, so it
doesn't matter what they are.
*/
Weights are passed as integers. In particular, the weight passed by
difference is one. This works fine in the int value and float value
cases but makes no sense in the object value case. In the object
value case, we don't do merging, so we don't use the weights, so it
doesn't matter what they are.
*/
#ifdef MERGE
VALUE_TYPE
w1
,
VALUE_TYPE
w2
,
#else
...
...
@@ -238,7 +238,7 @@ doesn't matter what they are.
SetIteration
t
;
int
i
;
/* See comment # 42 above */
/* See comment # 42 above */
#ifdef MERGE
VALUE_TYPE
v
;
#else
...
...
@@ -279,10 +279,10 @@ doesn't matter what they are.
{
TEST_KEY_SET_OR
(
cmp
,
i1
.
key
,
i2
.
key
)
goto
err
;
if
(
cmp
<
0
)
{
if
(
c1
)
{
if
(
r
->
len
>=
r
->
size
&&
Bucket_grow
(
r
,
-
1
,
!
merge
)
<
0
)
goto
err
;
{
if
(
c1
)
{
if
(
r
->
len
>=
r
->
size
&&
Bucket_grow
(
r
,
-
1
,
!
merge
)
<
0
)
goto
err
;
COPY_KEY
(
r
->
keys
[
r
->
len
],
i1
.
key
);
INCREF_KEY
(
r
->
keys
[
r
->
len
]);
if
(
merge
)
...
...
@@ -290,15 +290,15 @@ doesn't matter what they are.
COPY_VALUE
(
r
->
values
[
r
->
len
],
MERGE_WEIGHT
(
i1
.
value
,
w1
));
INCREF_VALUE
(
r
->
values
[
r
->
len
]);
}
r
->
len
++
;
}
r
->
len
++
;
}
if
(
i1
.
next
(
&
i1
)
<
0
)
goto
err
;
}
}
else
if
(
cmp
==
0
)
{
if
(
c12
)
{
if
(
r
->
len
>=
r
->
size
&&
Bucket_grow
(
r
,
-
1
,
!
merge
)
<
0
)
goto
err
;
{
if
(
c12
)
{
if
(
r
->
len
>=
r
->
size
&&
Bucket_grow
(
r
,
-
1
,
!
merge
)
<
0
)
goto
err
;
COPY_KEY
(
r
->
keys
[
r
->
len
],
i1
.
key
);
INCREF_KEY
(
r
->
keys
[
r
->
len
]);
if
(
merge
)
...
...
@@ -310,16 +310,16 @@ doesn't matter what they are.
INCREF_VALUE
(
r
->
values
[
r
->
len
]);
#endif
}
r
->
len
++
;
}
r
->
len
++
;
}
if
(
i1
.
next
(
&
i1
)
<
0
)
goto
err
;
if
(
i2
.
next
(
&
i2
)
<
0
)
goto
err
;
}
}
else
{
if
(
c2
)
{
if
(
r
->
len
>=
r
->
size
&&
Bucket_grow
(
r
,
-
1
,
!
merge
)
<
0
)
goto
err
;
{
if
(
c2
)
{
if
(
r
->
len
>=
r
->
size
&&
Bucket_grow
(
r
,
-
1
,
!
merge
)
<
0
)
goto
err
;
COPY_KEY
(
r
->
keys
[
r
->
len
],
i2
.
key
);
INCREF_KEY
(
r
->
keys
[
r
->
len
]);
if
(
merge
)
...
...
@@ -327,10 +327,10 @@ doesn't matter what they are.
COPY_VALUE
(
r
->
values
[
r
->
len
],
MERGE_WEIGHT
(
i2
.
value
,
w2
));
INCREF_VALUE
(
r
->
values
[
r
->
len
]);
}
r
->
len
++
;
}
r
->
len
++
;
}
if
(
i2
.
next
(
&
i2
)
<
0
)
goto
err
;
}
}
}
if
(
c1
&&
copyRemaining
(
r
,
&
i1
,
merge
,
w1
)
<
0
)
goto
err
;
if
(
c2
&&
copyRemaining
(
r
,
&
i2
,
merge
,
w2
)
<
0
)
goto
err
;
...
...
@@ -342,11 +342,11 @@ doesn't matter what they are.
return
OBJECT
(
r
);
#ifndef MERGE_DEFAULT
invalid_set_operation:
invalid_set_operation:
PyErr_SetString
(
PyExc_TypeError
,
"invalid set operation"
);
#endif
err:
err:
finiSetIteration
(
&
i1
);
finiSetIteration
(
&
i2
);
Py_XDECREF
(
r
);
...
...
@@ -461,7 +461,7 @@ wintersection_m(PyObject *ignored, PyObject *args)
o1
=
set_operation
(
o1
,
o2
,
1
,
1
,
w1
,
w2
,
0
,
1
,
0
);
if
(
o1
)
ASSIGN
(
o1
,
Py_BuildValue
(
VALUE_PARSE
"O"
,
((
o1
->
ob_type
==
(
PyTypeObject
*
)(
&
SetType
))
?
w2
+
w1
:
1
),
((
o1
->
ob_type
==
(
PyTypeObject
*
)(
&
SetType
))
?
w2
+
w1
:
1
),
o1
));
return
o1
;
...
...
@@ -479,79 +479,79 @@ wintersection_m(PyObject *ignored, PyObject *args)
static
PyObject
*
multiunion_m
(
PyObject
*
ignored
,
PyObject
*
args
)
{
PyObject
*
seq
;
/* input sequence */
int
n
;
/* length of input sequence */
PyObject
*
set
=
NULL
;
/* an element of the input sequence */
Bucket
*
result
;
/* result set */
SetIteration
setiter
=
{
0
};
int
i
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"O"
,
&
seq
))
return
NULL
;
n
=
PyObject_Length
(
seq
);
if
(
n
<
0
)
return
NULL
;
/* Construct an empty result set. */
result
=
BUCKET
(
PyObject_CallObject
(
OBJECT
(
&
SetType
),
NULL
));
if
(
result
==
NULL
)
return
NULL
;
/* For each set in the input sequence, append its elements to the result
set. At this point, we ignore the possibility of duplicates. */
for
(
i
=
0
;
i
<
n
;
++
i
)
{
set
=
PySequence_GetItem
(
seq
,
i
);
if
(
set
==
NULL
)
goto
Error
;
/* If set is a bucket, do a straight resize + memcpy. */
if
(
set
->
ob_type
==
(
PyTypeObject
*
)
&
SetType
||
set
->
ob_type
==
(
PyTypeObject
*
)
&
BucketType
)
{
Bucket
*
b
=
BUCKET
(
set
);
int
status
=
0
;
UNLESS
(
PER_USE
(
b
))
goto
Error
;
if
(
b
->
len
)
status
=
bucket_append
(
result
,
b
,
0
,
b
->
len
,
0
,
i
<
n
-
1
);
PER_UNUSE
(
b
);
if
(
status
<
0
)
goto
Error
;
}
else
{
/* No cheap way: iterate over set's elements one at a time. */
if
(
initSetIteration
(
&
setiter
,
set
,
0
)
<
0
)
goto
Error
;
if
(
setiter
.
next
(
&
setiter
)
<
0
)
goto
Error
;
while
(
setiter
.
position
>=
0
)
{
if
(
result
->
len
>=
result
->
size
&&
Bucket_grow
(
result
,
-
1
,
1
)
<
0
)
goto
Error
;
COPY_KEY
(
result
->
keys
[
result
->
len
],
setiter
.
key
);
++
result
->
len
;
/* We know the key is an int, so no need to incref it. */
if
(
setiter
.
next
(
&
setiter
)
<
0
)
goto
Error
;
}
finiSetIteration
(
&
setiter
);
}
Py_DECREF
(
set
);
set
=
NULL
;
}
PyObject
*
seq
;
/* input sequence */
int
n
;
/* length of input sequence */
PyObject
*
set
=
NULL
;
/* an element of the input sequence */
Bucket
*
result
;
/* result set */
SetIteration
setiter
=
{
0
};
int
i
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"O"
,
&
seq
))
return
NULL
;
/* Combine, sort, remove duplicates, and reset the result's len.
If the set shrinks (which happens if and only if there are
duplicates), no point to realloc'ing the set smaller, as we
expect the result set to be short-lived.
*/
if
(
result
->
len
>
0
)
{
size_t
newlen
;
/* number of elements in final result set */
newlen
=
sort_int_nodups
(
result
->
keys
,
(
size_t
)
result
->
len
);
result
->
len
=
(
int
)
newlen
;
}
return
(
PyObject
*
)
result
;
n
=
PyObject_Length
(
seq
);
if
(
n
<
0
)
return
NULL
;
Error:
Py_DECREF
(
result
);
Py_XDECREF
(
set
);
finiSetIteration
(
&
setiter
);
/* Construct an empty result set. */
result
=
BUCKET
(
PyObject_CallObject
(
OBJECT
(
&
SetType
),
NULL
));
if
(
result
==
NULL
)
return
NULL
;
/* For each set in the input sequence, append its elements to the result
set. At this point, we ignore the possibility of duplicates. */
for
(
i
=
0
;
i
<
n
;
++
i
)
{
set
=
PySequence_GetItem
(
seq
,
i
);
if
(
set
==
NULL
)
goto
Error
;
/* If set is a bucket, do a straight resize + memcpy. */
if
(
set
->
ob_type
==
(
PyTypeObject
*
)
&
SetType
||
set
->
ob_type
==
(
PyTypeObject
*
)
&
BucketType
)
{
Bucket
*
b
=
BUCKET
(
set
);
int
status
=
0
;
UNLESS
(
PER_USE
(
b
))
goto
Error
;
if
(
b
->
len
)
status
=
bucket_append
(
result
,
b
,
0
,
b
->
len
,
0
,
i
<
n
-
1
);
PER_UNUSE
(
b
);
if
(
status
<
0
)
goto
Error
;
}
else
{
/* No cheap way: iterate over set's elements one at a time. */
if
(
initSetIteration
(
&
setiter
,
set
,
0
)
<
0
)
goto
Error
;
if
(
setiter
.
next
(
&
setiter
)
<
0
)
goto
Error
;
while
(
setiter
.
position
>=
0
)
{
if
(
result
->
len
>=
result
->
size
&&
Bucket_grow
(
result
,
-
1
,
1
)
<
0
)
goto
Error
;
COPY_KEY
(
result
->
keys
[
result
->
len
],
setiter
.
key
);
++
result
->
len
;
/* We know the key is an int, so no need to incref it. */
if
(
setiter
.
next
(
&
setiter
)
<
0
)
goto
Error
;
}
finiSetIteration
(
&
setiter
);
}
Py_DECREF
(
set
);
set
=
NULL
;
}
/* Combine, sort, remove duplicates, and reset the result's len.
If the set shrinks (which happens if and only if there are
duplicates), no point to realloc'ing the set smaller, as we
expect the result set to be short-lived.
*/
if
(
result
->
len
>
0
)
{
size_t
newlen
;
/* number of elements in final result set */
newlen
=
sort_int_nodups
(
result
->
keys
,
(
size_t
)
result
->
len
);
result
->
len
=
(
int
)
newlen
;
}
return
(
PyObject
*
)
result
;
Error:
Py_DECREF
(
result
);
Py_XDECREF
(
set
);
finiSetIteration
(
&
setiter
);
return
NULL
;
}
#endif
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