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
a43f15e5
Commit
a43f15e5
authored
Feb 03, 2005
by
Dmitry Vasiliev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimization: use iterators where possible
parent
692b69ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
23 deletions
+71
-23
src/ZODB/fsIndex.py
src/ZODB/fsIndex.py
+19
-19
src/ZODB/tests/testfsIndex.py
src/ZODB/tests/testfsIndex.py
+52
-4
No files found.
src/ZODB/fsIndex.py
View file @
a43f15e5
...
...
@@ -48,7 +48,7 @@ def num2str(n):
def
str2num
(
s
):
return
struct
.
unpack
(
">Q"
,
"
\
000
\
000
"
+
s
)[
0
]
class
fsIndex
:
class
fsIndex
(
object
)
:
def
__init__
(
self
):
self
.
_data
=
{}
...
...
@@ -76,7 +76,7 @@ class fsIndex:
def
__len__
(
self
):
r
=
0
for
tree
in
self
.
_data
.
values
():
for
tree
in
self
.
_data
.
iter
values
():
r
+=
len
(
tree
)
return
r
...
...
@@ -85,7 +85,7 @@ class fsIndex:
self
[
k
]
=
v
def
has_key
(
self
,
key
):
v
=
self
.
get
(
key
,
self
)
v
=
self
.
get
(
key
,
self
)
return
v
is
not
self
def
__contains__
(
self
,
key
):
...
...
@@ -101,27 +101,27 @@ class fsIndex:
self
.
_data
.
clear
()
def
__iter__
(
self
):
for
prefix
,
tree
in
self
.
_data
.
items
():
for
prefix
,
tree
in
self
.
_data
.
ite
rite
ms
():
for
suffix
in
tree
:
yield
prefix
+
suffix
iterkeys
=
__iter__
def
keys
(
self
):
r
=
[]
for
prefix
,
tree
in
self
.
_data
.
items
():
for
suffix
in
tree
.
keys
():
r
.
append
(
prefix
+
suffix
)
return
r
return
list
(
self
.
iterkeys
())
def
iteritems
(
self
):
for
prefix
,
tree
in
self
.
_data
.
iteritems
():
for
suffix
,
value
in
tree
.
iteritems
():
yield
(
prefix
+
suffix
,
str2num
(
value
))
def
items
(
self
):
r
=
[]
for
prefix
,
tree
in
self
.
_data
.
items
():
for
suffix
,
v
in
tree
.
items
():
r
.
append
(((
prefix
+
suffix
),
str2num
(
v
)))
return
r
return
list
(
self
.
iteritems
())
def
itervalues
(
self
):
for
tree
in
self
.
_data
.
itervalues
():
for
value
in
tree
.
itervalues
():
yield
str2num
(
value
)
def
values
(
self
):
r
=
[]
for
prefix
,
tree
in
self
.
_data
.
items
():
for
v
in
tree
.
values
():
r
.
append
(
str2num
(
v
))
return
r
return
list
(
self
.
itervalues
())
src/ZODB/tests/testfsIndex.py
View file @
a43f15e5
...
...
@@ -18,11 +18,14 @@ from ZODB.utils import p64
class
Test
(
unittest
.
TestCase
):
def
testInserts
(
self
):
index
=
fsIndex
()
def
setUp
(
self
):
self
.
index
=
fsIndex
()
for
i
in
range
(
200
):
index
[
p64
(
i
*
1000
)]
=
(
i
*
1000L
+
1
)
self
.
index
[
p64
(
i
*
1000
)]
=
(
i
*
1000L
+
1
)
def
testInserts
(
self
):
index
=
self
.
index
for
i
in
range
(
0
,
200
):
self
.
assertEqual
((
i
,
index
[
p64
(
i
*
1000
)]),
(
i
,(
i
*
1000L
+
1
)))
...
...
@@ -40,7 +43,7 @@ class Test(unittest.TestCase):
# self.failUnless(len(index._data) > 1)
def
testUpdate
(
self
):
index
=
fsIndex
()
index
=
self
.
index
d
=
{}
for
i
in
range
(
200
):
...
...
@@ -63,6 +66,51 @@ class Test(unittest.TestCase):
self
.
assertEqual
(
index
.
get
(
p64
(
399000
)),
399002
)
self
.
assertEqual
(
len
(
index
),
600
)
def
testKeys
(
self
):
keys
=
list
(
iter
(
self
.
index
))
keys
.
sort
()
for
i
,
k
in
enumerate
(
keys
):
self
.
assertEqual
(
k
,
p64
(
i
*
1000
))
keys
=
list
(
self
.
index
.
iterkeys
())
keys
.
sort
()
for
i
,
k
in
enumerate
(
keys
):
self
.
assertEqual
(
k
,
p64
(
i
*
1000
))
keys
=
self
.
index
.
keys
()
keys
.
sort
()
for
i
,
k
in
enumerate
(
keys
):
self
.
assertEqual
(
k
,
p64
(
i
*
1000
))
def
testValues
(
self
):
values
=
list
(
self
.
index
.
itervalues
())
values
.
sort
()
for
i
,
v
in
enumerate
(
values
):
self
.
assertEqual
(
v
,
(
i
*
1000L
+
1
))
values
=
self
.
index
.
values
()
values
.
sort
()
for
i
,
v
in
enumerate
(
values
):
self
.
assertEqual
(
v
,
(
i
*
1000L
+
1
))
def
testItems
(
self
):
items
=
list
(
self
.
index
.
iteritems
())
items
.
sort
()
for
i
,
item
in
enumerate
(
items
):
self
.
assertEqual
(
item
,
(
p64
(
i
*
1000
),
(
i
*
1000L
+
1
)))
items
=
self
.
index
.
items
()
items
.
sort
()
for
i
,
item
in
enumerate
(
items
):
self
.
assertEqual
(
item
,
(
p64
(
i
*
1000
),
(
i
*
1000L
+
1
)))
def
test_suite
():
loader
=
unittest
.
TestLoader
()
...
...
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