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
dbebf6dc
Commit
dbebf6dc
authored
Nov 12, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prefer '__contains__', w/ 'has_key' as alias.
Remove moar 'else-after-return'.
parent
9798b34b
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
308 additions
and
16 deletions
+308
-16
BTrees/_base.py
BTrees/_base.py
+15
-16
BTrees/tests/test__base.py
BTrees/tests/test__base.py
+293
-0
No files found.
BTrees/_base.py
View file @
dbebf6dc
...
...
@@ -75,14 +75,13 @@ class _BucketBase(_Base):
return
self
.
_keys
[
0
]
key
=
self
.
_to_key
(
key
)
index
=
self
.
_search
(
key
)
if
index
>
-
0
:
if
index
>
=
0
:
return
key
index
=
-
index
-
1
if
index
<
len
(
self
.
_keys
):
return
self
.
_keys
[
index
]
else
:
index
=
-
index
-
1
if
index
<
len
(
self
.
_keys
):
return
self
.
_keys
[
index
]
else
:
raise
ValueError
(
"no key satisfies the conditions"
)
raise
ValueError
(
"no key satisfies the conditions"
)
def
maxKey
(
self
,
key
=
_marker
):
if
key
is
_marker
:
...
...
@@ -140,13 +139,13 @@ class _BucketBase(_Base):
def
__iter__
(
self
):
return
iter
(
self
.
_keys
)
def
has_key
(
self
,
key
):
return
(
self
.
_search
(
self
.
_to_key
(
key
))
>=
0
)
and
1
def
__contains__
(
self
,
key
):
return
(
self
.
_search
(
self
.
_to_key
(
key
))
>=
0
)
__contains__
=
has_key
has_key
=
__contains__
def
_p_resolveConflict
(
self
,
*
states
):
set
=
not
hasattr
(
self
,
'_values'
)
is_set
=
getattr
(
self
,
'_values'
,
None
)
is
not
None
buckets
=
[]
for
state
in
states
:
...
...
@@ -171,7 +170,7 @@ class _BucketBase(_Base):
result
=
self
.
__class__
()
if
set
:
if
is_
set
:
def
merge_output
(
it
):
result
.
_keys
.
append
(
it
.
key
)
it
.
advance
()
...
...
@@ -186,7 +185,7 @@ class _BucketBase(_Base):
cmp13
=
cmp
(
i1
.
key
,
i3
.
key
)
if
cmp12
==
0
:
if
cmp13
==
0
:
if
set
:
if
is_
set
:
result
.
add
(
i1
.
key
)
elif
i2
.
value
==
i1
.
value
:
result
[
i1
.
key
]
=
i3
.
value
...
...
@@ -199,7 +198,7 @@ class _BucketBase(_Base):
i3
.
advance
()
elif
(
cmp13
>
0
):
# insert in new
merge_output
(
i3
)
elif
set
or
i1
.
value
==
i2
.
value
:
# deleted new
elif
is_
set
or
i1
.
value
==
i2
.
value
:
# deleted new
if
i3
.
position
==
1
:
# Deleted the first item. This will modify the
# parent node, so we don't know if merging will be
...
...
@@ -212,7 +211,7 @@ class _BucketBase(_Base):
elif
cmp13
==
0
:
if
cmp12
>
0
:
# insert committed
merge_output
(
i2
)
elif
set
or
i1
.
value
==
i3
.
value
:
# delete committed
elif
is_
set
or
i1
.
value
==
i3
.
value
:
# delete committed
if
i2
.
position
==
1
:
# Deleted the first item. This will modify the
# parent node, so we don't know if merging will be
...
...
@@ -249,7 +248,7 @@ class _BucketBase(_Base):
cmp12
=
cmp
(
i1
.
key
,
i2
.
key
)
if
cmp12
>
0
:
# insert committed
merge_output
(
i2
)
elif
cmp12
==
0
and
(
set
or
i1
.
value
==
i2
.
value
):
# deleted
in new
elif
cmp12
==
0
and
(
is_set
or
i1
.
value
==
i2
.
value
):
# del
in new
i1
.
advance
()
i2
.
advance
()
else
:
# dueling deletes or delete and change
...
...
@@ -259,7 +258,7 @@ class _BucketBase(_Base):
cmp13
=
cmp
(
i1
.
key
,
i3
.
key
)
if
cmp13
>
0
:
# insert new
merge_output
(
i3
)
elif
cmp13
==
0
and
(
set
or
i1
.
value
==
i3
.
value
):
elif
cmp13
==
0
and
(
is_
set
or
i1
.
value
==
i3
.
value
):
# deleted in committed
i1
.
advance
()
i3
.
advance
()
...
...
BTrees/tests/test__base.py
View file @
dbebf6dc
This diff is collapsed.
Click to expand it.
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