Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
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
ZEO
Commits
585f31ad
Commit
585f31ad
authored
Jun 09, 2002
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trimmed trailing whitespace.
parent
5721bdd2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
52 deletions
+52
-52
src/BTrees/BTreeItemsTemplate.c
src/BTrees/BTreeItemsTemplate.c
+52
-52
No files found.
src/BTrees/BTreeItemsTemplate.c
View file @
585f31ad
...
@@ -2,17 +2,17 @@
...
@@ -2,17 +2,17 @@
Copyright (c) 2001, 2002 Zope Corporation and Contributors.
Copyright (c) 2001, 2002 Zope Corporation and Contributors.
All Rights Reserved.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
This software is subject to the provisions of the Zope Public License,
Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE
FOR A PARTICULAR PURPOSE
****************************************************************************/
****************************************************************************/
#define BTREEITEMSTEMPLATE_C "$Id: BTreeItemsTemplate.c,v 1.
9 2002/03/08 18:33:01 jeremy
Exp $\n"
#define BTREEITEMSTEMPLATE_C "$Id: BTreeItemsTemplate.c,v 1.
10 2002/06/09 17:19:05 tim_one
Exp $\n"
typedef
struct
{
typedef
struct
{
PyObject_HEAD
PyObject_HEAD
...
@@ -28,7 +28,7 @@ typedef struct {
...
@@ -28,7 +28,7 @@ typedef struct {
#define ITEMS(O)((BTreeItems*)(O))
#define ITEMS(O)((BTreeItems*)(O))
static
PyObject
*
static
PyObject
*
newBTreeItems
(
char
kind
,
newBTreeItems
(
char
kind
,
Bucket
*
lowbucket
,
int
lowoffset
,
Bucket
*
lowbucket
,
int
lowoffset
,
Bucket
*
highbucket
,
int
highoffset
);
Bucket
*
highbucket
,
int
highoffset
);
...
@@ -41,7 +41,7 @@ BTreeItems_dealloc(BTreeItems *self)
...
@@ -41,7 +41,7 @@ BTreeItems_dealloc(BTreeItems *self)
PyObject_DEL
(
self
);
PyObject_DEL
(
self
);
}
}
static
int
static
int
BTreeItems_length_or_nonzero
(
BTreeItems
*
self
,
int
nonzero
)
BTreeItems_length_or_nonzero
(
BTreeItems
*
self
,
int
nonzero
)
{
{
int
r
;
int
r
;
...
@@ -52,7 +52,7 @@ BTreeItems_length_or_nonzero(BTreeItems *self, int nonzero)
...
@@ -52,7 +52,7 @@ BTreeItems_length_or_nonzero(BTreeItems *self, int nonzero)
r
=
self
->
last
+
1
-
self
->
first
;
r
=
self
->
last
+
1
-
self
->
first
;
if
(
nonzero
&&
r
>
0
)
if
(
nonzero
&&
r
>
0
)
/* Short-circuit if all we care about is nonempty */
/* Short-circuit if all we care about is nonempty */
return
1
;
return
1
;
...
@@ -60,14 +60,14 @@ BTreeItems_length_or_nonzero(BTreeItems *self, int nonzero)
...
@@ -60,14 +60,14 @@ BTreeItems_length_or_nonzero(BTreeItems *self, int nonzero)
Py_INCREF
(
b
);
Py_INCREF
(
b
);
PER_USE_OR_RETURN
(
b
,
-
1
);
PER_USE_OR_RETURN
(
b
,
-
1
);
while
((
next
=
b
->
next
))
while
((
next
=
b
->
next
))
{
{
r
+=
b
->
len
;
r
+=
b
->
len
;
if
(
nonzero
&&
r
>
0
)
if
(
nonzero
&&
r
>
0
)
/* Short-circuit if all we care about is nonempty */
/* Short-circuit if all we care about is nonempty */
break
;
break
;
if
(
next
==
self
->
lastbucket
)
if
(
next
==
self
->
lastbucket
)
break
;
/* we already counted the last bucket */
break
;
/* we already counted the last bucket */
Py_INCREF
(
next
);
Py_INCREF
(
next
);
...
@@ -86,7 +86,7 @@ BTreeItems_length_or_nonzero(BTreeItems *self, int nonzero)
...
@@ -86,7 +86,7 @@ BTreeItems_length_or_nonzero(BTreeItems *self, int nonzero)
static
int
static
int
BTreeItems_length
(
BTreeItems
*
self
)
BTreeItems_length
(
BTreeItems
*
self
)
{
{
return
BTreeItems_length_or_nonzero
(
self
,
0
);
return
BTreeItems_length_or_nonzero
(
self
,
0
);
}
}
...
@@ -104,7 +104,7 @@ BTreeItems_length( BTreeItems *self)
...
@@ -104,7 +104,7 @@ BTreeItems_length( BTreeItems *self)
** Returns 0 if successful, -1 on failure to seek
** Returns 0 if successful, -1 on failure to seek
*/
*/
static
int
static
int
BTreeItems_seek
(
BTreeItems
*
self
,
int
i
)
BTreeItems_seek
(
BTreeItems
*
self
,
int
i
)
{
{
int
delta
,
pseudoindex
,
currentoffset
;
int
delta
,
pseudoindex
,
currentoffset
;
Bucket
*
b
,
*
currentbucket
;
Bucket
*
b
,
*
currentbucket
;
...
@@ -121,8 +121,8 @@ BTreeItems_seek(BTreeItems *self, int i)
...
@@ -121,8 +121,8 @@ BTreeItems_seek(BTreeItems *self, int i)
currentoffset
=
self
->
currentoffset
;
currentoffset
=
self
->
currentoffset
;
/* Make sure that the index and psuedoindex have the same sign */
/* Make sure that the index and psuedoindex have the same sign */
if
(
pseudoindex
<
0
&&
i
>=
0
)
if
(
pseudoindex
<
0
&&
i
>=
0
)
{
{
/* Position to the start of the sequence. */
/* Position to the start of the sequence. */
ASSIGNB
(
currentbucket
,
self
->
firstbucket
);
ASSIGNB
(
currentbucket
,
self
->
firstbucket
);
Py_INCREF
(
currentbucket
);
Py_INCREF
(
currentbucket
);
...
@@ -140,14 +140,14 @@ BTreeItems_seek(BTreeItems *self, int i)
...
@@ -140,14 +140,14 @@ BTreeItems_seek(BTreeItems *self, int i)
}
}
}
}
pseudoindex
=
0
;
pseudoindex
=
0
;
}
}
else
if
(
self
->
pseudoindex
>=
0
&&
i
<
0
)
else
if
(
self
->
pseudoindex
>=
0
&&
i
<
0
)
{
{
/* Position to the end of the sequence. */
/* Position to the end of the sequence. */
ASSIGNBC
(
currentbucket
,
self
->
lastbucket
);
ASSIGNBC
(
currentbucket
,
self
->
lastbucket
);
currentoffset
=
self
->
last
;
currentoffset
=
self
->
last
;
UNLESS
(
PER_USE
(
currentbucket
))
goto
err
;
UNLESS
(
PER_USE
(
currentbucket
))
goto
err
;
/* We need to be careful that we have a valid offset! */
/* We need to be careful that we have a valid offset! */
if
(
currentoffset
>=
currentbucket
->
len
)
if
(
currentoffset
>=
currentbucket
->
len
)
{
{
...
@@ -163,30 +163,30 @@ BTreeItems_seek(BTreeItems *self, int i)
...
@@ -163,30 +163,30 @@ BTreeItems_seek(BTreeItems *self, int i)
else
else
{
{
UNLESS
(
PER_USE
(
currentbucket
))
goto
err
;
UNLESS
(
PER_USE
(
currentbucket
))
goto
err
;
/* We need to be careful that we have a valid offset! */
/* We need to be careful that we have a valid offset! */
if
(
currentoffset
>=
currentbucket
->
len
)
goto
no_match
;
if
(
currentoffset
>=
currentbucket
->
len
)
goto
no_match
;
}
}
/* Whew, we got here so we have a valid offset! */
/* Whew, we got here so we have a valid offset! */
delta
=
i
-
pseudoindex
;
delta
=
i
-
pseudoindex
;
if
(
delta
)
if
(
delta
)
while
(
delta
)
while
(
delta
)
{
{
if
(
delta
<
0
)
if
(
delta
<
0
)
{
{
/* First, would we drop below zero? */
/* First, would we drop below zero? */
if
(
pseudoindex
>=
0
&&
pseudoindex
+
delta
<
0
)
goto
no_match
;
if
(
pseudoindex
>=
0
&&
pseudoindex
+
delta
<
0
)
goto
no_match
;
/* Next, do we have to backup a bucket? */
/* Next, do we have to backup a bucket? */
if
(
currentoffset
+
delta
<
0
)
if
(
currentoffset
+
delta
<
0
)
{
{
if
(
currentbucket
==
self
->
firstbucket
)
goto
no_match
;
if
(
currentbucket
==
self
->
firstbucket
)
goto
no_match
;
b
=
PreviousBucket
(
currentbucket
,
self
->
firstbucket
,
i
);
b
=
PreviousBucket
(
currentbucket
,
self
->
firstbucket
,
i
);
if
(
b
==
NULL
)
goto
no_match
;
if
(
b
==
NULL
)
goto
no_match
;
PER_ALLOW_DEACTIVATION
(
currentbucket
);
PER_ALLOW_DEACTIVATION
(
currentbucket
);
PER_ACCESSED
(
currentbucket
);
PER_ACCESSED
(
currentbucket
);
ASSIGNB
(
currentbucket
,
b
);
ASSIGNB
(
currentbucket
,
b
);
...
@@ -199,7 +199,7 @@ BTreeItems_seek(BTreeItems *self, int i)
...
@@ -199,7 +199,7 @@ BTreeItems_seek(BTreeItems *self, int i)
/* We backed into an empty bucket. Fix the psuedo index */
/* We backed into an empty bucket. Fix the psuedo index */
if
(
++
pseudoindex
==
0
)
goto
no_match
;
if
(
++
pseudoindex
==
0
)
goto
no_match
;
}
}
else
else
{
/* Local adjustment */
{
/* Local adjustment */
pseudoindex
+=
delta
;
pseudoindex
+=
delta
;
currentoffset
+=
delta
;
currentoffset
+=
delta
;
...
@@ -208,16 +208,16 @@ BTreeItems_seek(BTreeItems *self, int i)
...
@@ -208,16 +208,16 @@ BTreeItems_seek(BTreeItems *self, int i)
if
(
currentbucket
==
self
->
firstbucket
&&
if
(
currentbucket
==
self
->
firstbucket
&&
currentoffset
<
self
->
first
)
goto
no_match
;
currentoffset
<
self
->
first
)
goto
no_match
;
}
}
else
if
(
delta
>
0
)
else
if
(
delta
>
0
)
{
{
/* Simple backwards range check */
/* Simple backwards range check */
if
(
pseudoindex
<
0
&&
pseudoindex
+
delta
>=
0
)
if
(
pseudoindex
<
0
&&
pseudoindex
+
delta
>=
0
)
goto
no_match
;
goto
no_match
;
/* Next, do we go forward a bucket? */
/* Next, do we go forward a bucket? */
if
(
currentoffset
+
delta
>=
currentbucket
->
len
)
if
(
currentoffset
+
delta
>=
currentbucket
->
len
)
{
{
while
(
1
)
while
(
1
)
{
{
...
@@ -233,7 +233,7 @@ BTreeItems_seek(BTreeItems *self, int i)
...
@@ -233,7 +233,7 @@ BTreeItems_seek(BTreeItems *self, int i)
UNLESS
(
PER_USE
(
currentbucket
))
goto
err
;
UNLESS
(
PER_USE
(
currentbucket
))
goto
err
;
currentoffset
=
0
;
currentoffset
=
0
;
if
(
currentbucket
->
len
)
break
;
if
(
currentbucket
->
len
)
break
;
}
}
}
}
else
else
{
/* Local adjustment */
{
/* Local adjustment */
...
@@ -242,7 +242,7 @@ BTreeItems_seek(BTreeItems *self, int i)
...
@@ -242,7 +242,7 @@ BTreeItems_seek(BTreeItems *self, int i)
}
}
if
(
currentbucket
==
self
->
lastbucket
&&
if
(
currentbucket
==
self
->
lastbucket
&&
currentoffset
>
self
->
last
)
goto
no_match
;
currentoffset
>
self
->
last
)
goto
no_match
;
}
}
delta
=
i
-
pseudoindex
;
delta
=
i
-
pseudoindex
;
...
@@ -262,13 +262,13 @@ BTreeItems_seek(BTreeItems *self, int i)
...
@@ -262,13 +262,13 @@ BTreeItems_seek(BTreeItems *self, int i)
self
->
pseudoindex
=
pseudoindex
;
self
->
pseudoindex
=
pseudoindex
;
self
->
currentoffset
=
currentoffset
;
self
->
currentoffset
=
currentoffset
;
return
0
;
return
0
;
no_match:
no_match:
IndexError
(
i
);
IndexError
(
i
);
PER_ALLOW_DEACTIVATION
(
currentbucket
);
PER_ALLOW_DEACTIVATION
(
currentbucket
);
err:
err:
...
@@ -290,21 +290,21 @@ static PyObject *
...
@@ -290,21 +290,21 @@ static PyObject *
BTreeItems_item
(
BTreeItems
*
self
,
int
i
)
BTreeItems_item
(
BTreeItems
*
self
,
int
i
)
{
{
PyObject
*
r
,
*
k
=
0
,
*
v
=
0
;
PyObject
*
r
,
*
k
=
0
,
*
v
=
0
;
if
(
BTreeItems_seek
(
self
,
i
)
<
0
)
return
NULL
;
if
(
BTreeItems_seek
(
self
,
i
)
<
0
)
return
NULL
;
PER_USE_OR_RETURN
(
self
->
currentbucket
,
NULL
);
PER_USE_OR_RETURN
(
self
->
currentbucket
,
NULL
);
switch
(
self
->
kind
)
{
switch
(
self
->
kind
)
{
case
'v'
:
case
'v'
:
COPY_VALUE_TO_OBJECT
(
r
,
self
->
currentbucket
->
values
[
self
->
currentoffset
]);
COPY_VALUE_TO_OBJECT
(
r
,
self
->
currentbucket
->
values
[
self
->
currentoffset
]);
break
;
break
;
case
'i'
:
case
'i'
:
COPY_KEY_TO_OBJECT
(
k
,
self
->
currentbucket
->
keys
[
self
->
currentoffset
]);
COPY_KEY_TO_OBJECT
(
k
,
self
->
currentbucket
->
keys
[
self
->
currentoffset
]);
UNLESS
(
k
)
return
NULL
;
UNLESS
(
k
)
return
NULL
;
COPY_VALUE_TO_OBJECT
(
v
,
self
->
currentbucket
->
values
[
self
->
currentoffset
]);
COPY_VALUE_TO_OBJECT
(
v
,
self
->
currentbucket
->
values
[
self
->
currentoffset
]);
UNLESS
(
v
)
return
NULL
;
UNLESS
(
v
)
return
NULL
;
...
@@ -339,7 +339,7 @@ BTreeItems_item(BTreeItems *self, int i)
...
@@ -339,7 +339,7 @@ BTreeItems_item(BTreeItems *self, int i)
** ilow The start index
** ilow The start index
** ihigh The end index
** ihigh The end index
**
**
** Returns: BTreeItems item
** Returns: BTreeItems item
*/
*/
static
PyObject
*
static
PyObject
*
BTreeItems_slice
(
BTreeItems
*
self
,
int
ilow
,
int
ihigh
)
BTreeItems_slice
(
BTreeItems
*
self
,
int
ilow
,
int
ihigh
)
...
@@ -348,19 +348,19 @@ BTreeItems_slice(BTreeItems *self, int ilow, int ihigh)
...
@@ -348,19 +348,19 @@ BTreeItems_slice(BTreeItems *self, int ilow, int ihigh)
Bucket
*
highbucket
;
Bucket
*
highbucket
;
int
lowoffset
;
int
lowoffset
;
int
highoffset
;
int
highoffset
;
if
(
BTreeItems_seek
(
self
,
ilow
)
<
0
)
return
NULL
;
if
(
BTreeItems_seek
(
self
,
ilow
)
<
0
)
return
NULL
;
lowbucket
=
self
->
currentbucket
;
lowbucket
=
self
->
currentbucket
;
lowoffset
=
self
->
currentoffset
;
lowoffset
=
self
->
currentoffset
;
if
(
BTreeItems_seek
(
self
,
ihigh
)
<
0
)
return
NULL
;
if
(
BTreeItems_seek
(
self
,
ihigh
)
<
0
)
return
NULL
;
highbucket
=
self
->
currentbucket
;
highbucket
=
self
->
currentbucket
;
highoffset
=
self
->
currentoffset
;
highoffset
=
self
->
currentoffset
;
return
newBTreeItems
(
self
->
kind
,
return
newBTreeItems
(
self
->
kind
,
lowbucket
,
lowoffset
,
highbucket
,
highoffset
);
lowbucket
,
lowoffset
,
highbucket
,
highoffset
);
}
}
...
@@ -405,19 +405,19 @@ static PyTypeObject BTreeItemsType = {
...
@@ -405,19 +405,19 @@ static PyTypeObject BTreeItemsType = {
(
reprfunc
)
0
,
/*tp_str*/
(
reprfunc
)
0
,
/*tp_str*/
0
,
/*tp_getattro*/
0
,
/*tp_getattro*/
0
,
/*tp_setattro*/
0
,
/*tp_setattro*/
/* Space for future expansion */
/* Space for future expansion */
0L
,
0L
,
0L
,
0L
,
"Sequence type used to iterate over BTree items."
/* Documentation string */
"Sequence type used to iterate over BTree items."
/* Documentation string */
};
};
static
PyObject
*
static
PyObject
*
newBTreeItems
(
char
kind
,
newBTreeItems
(
char
kind
,
Bucket
*
lowbucket
,
int
lowoffset
,
Bucket
*
lowbucket
,
int
lowoffset
,
Bucket
*
highbucket
,
int
highoffset
)
Bucket
*
highbucket
,
int
highoffset
)
{
{
BTreeItems
*
self
;
BTreeItems
*
self
;
UNLESS
(
self
=
PyObject_NEW
(
BTreeItems
,
&
BTreeItemsType
))
return
NULL
;
UNLESS
(
self
=
PyObject_NEW
(
BTreeItems
,
&
BTreeItemsType
))
return
NULL
;
self
->
kind
=
kind
;
self
->
kind
=
kind
;
...
@@ -446,7 +446,7 @@ newBTreeItems(char kind,
...
@@ -446,7 +446,7 @@ newBTreeItems(char kind,
return
OBJECT
(
self
);
return
OBJECT
(
self
);
}
}
static
int
static
int
nextBTreeItems
(
SetIteration
*
i
)
nextBTreeItems
(
SetIteration
*
i
)
{
{
if
(
i
->
position
>=
0
)
if
(
i
->
position
>=
0
)
...
@@ -456,7 +456,7 @@ nextBTreeItems(SetIteration *i)
...
@@ -456,7 +456,7 @@ nextBTreeItems(SetIteration *i)
DECREF_KEY
(
i
->
key
);
DECREF_KEY
(
i
->
key
);
DECREF_VALUE
(
i
->
value
);
DECREF_VALUE
(
i
->
value
);
}
}
if
(
BTreeItems_seek
(
ITEMS
(
i
->
set
),
i
->
position
)
>=
0
)
if
(
BTreeItems_seek
(
ITEMS
(
i
->
set
),
i
->
position
)
>=
0
)
{
{
Bucket
*
currentbucket
;
Bucket
*
currentbucket
;
...
@@ -468,9 +468,9 @@ nextBTreeItems(SetIteration *i)
...
@@ -468,9 +468,9 @@ nextBTreeItems(SetIteration *i)
COPY_KEY
(
i
->
key
,
currentbucket
->
keys
[
ITEMS
(
i
->
set
)
->
currentoffset
]);
COPY_KEY
(
i
->
key
,
currentbucket
->
keys
[
ITEMS
(
i
->
set
)
->
currentoffset
]);
INCREF_KEY
(
i
->
key
);
INCREF_KEY
(
i
->
key
);
COPY_VALUE
(
i
->
value
,
COPY_VALUE
(
i
->
value
,
currentbucket
->
values
[
ITEMS
(
i
->
set
)
->
currentoffset
]);
currentbucket
->
values
[
ITEMS
(
i
->
set
)
->
currentoffset
]);
COPY_VALUE
(
i
->
value
,
COPY_VALUE
(
i
->
value
,
BUCKET
(
ITEMS
(
i
->
set
)
->
currentbucket
)
BUCKET
(
ITEMS
(
i
->
set
)
->
currentbucket
)
->
values
[
ITEMS
(
i
->
set
)
->
currentoffset
]);
->
values
[
ITEMS
(
i
->
set
)
->
currentoffset
]);
INCREF_VALUE
(
i
->
value
);
INCREF_VALUE
(
i
->
value
);
...
@@ -488,7 +488,7 @@ nextBTreeItems(SetIteration *i)
...
@@ -488,7 +488,7 @@ nextBTreeItems(SetIteration *i)
return
0
;
return
0
;
}
}
static
int
static
int
nextTreeSetItems
(
SetIteration
*
i
)
nextTreeSetItems
(
SetIteration
*
i
)
{
{
if
(
i
->
position
>=
0
)
if
(
i
->
position
>=
0
)
...
@@ -497,7 +497,7 @@ nextTreeSetItems(SetIteration *i)
...
@@ -497,7 +497,7 @@ nextTreeSetItems(SetIteration *i)
{
{
DECREF_KEY
(
i
->
key
);
DECREF_KEY
(
i
->
key
);
}
}
if
(
BTreeItems_seek
(
ITEMS
(
i
->
set
),
i
->
position
)
>=
0
)
if
(
BTreeItems_seek
(
ITEMS
(
i
->
set
),
i
->
position
)
>=
0
)
{
{
Bucket
*
currentbucket
;
Bucket
*
currentbucket
;
...
...
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