Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EO Time Series Viewer
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Jakimow
EO Time Series Viewer
Commits
dad001b9
Commit
dad001b9
authored
11 years ago
by
Luke Campagnola
Browse files
Options
Downloads
Patches
Plain Diff
Style corrections
parent
eb339702
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyqtgraph/lru_cache.py
+35
-30
35 additions, 30 deletions
pyqtgraph/lru_cache.py
with
35 additions
and
30 deletions
pyqtgraph/lru_cache.py
+
35
−
30
View file @
dad001b9
...
@@ -10,33 +10,35 @@ class LRUCache(object):
...
@@ -10,33 +10,35 @@ class LRUCache(object):
This LRU cache should be reasonable for short collections (until around 100 items), as it does a
This LRU cache should be reasonable for short collections (until around 100 items), as it does a
sort on the items if the collection would become too big (so, it is very fast for getting and
sort on the items if the collection would become too big (so, it is very fast for getting and
setting but when its size would become higher than the max size it does one sort based on the
setting but when its size would become higher than the max size it does one sort based on the
internal time to decide which items should be removed -- which should be Ok if the resize
_t
o
internal time to decide which items should be removed -- which should be Ok if the resize
T
o
isn
'
t too close to the max
_s
ize so that it becomes an operation that doesn
'
t happen all the
isn
'
t too close to the max
S
ize so that it becomes an operation that doesn
'
t happen all the
time).
time).
'''
'''
def
__init__
(
self
,
max
_s
ize
=
100
,
resize
_t
o
=
70
):
def
__init__
(
self
,
max
S
ize
=
100
,
resize
T
o
=
70
):
'''
'''
:param int max_size:
============== =========================================================
This is the maximum size of the cache. When some item is added and the cache would become
**Arguments:**
bigger than this, it
'
s resized to the value passed on resize_to.
maxSize (int) This is the maximum size of the cache. When some
item is added and the cache would become bigger than
:param int resize_to:
this, it
'
s resized to the value passed on resizeTo.
When a resize operation happens, this is the size of the final cache.
resizeTo (int) When a resize operation happens, this is the size
of the final cache.
============== =========================================================
'''
'''
assert
resize
_t
o
<
max
_s
ize
assert
resize
T
o
<
max
S
ize
self
.
max
_s
ize
=
max
_s
ize
self
.
max
S
ize
=
max
S
ize
self
.
resize
_t
o
=
resize
_t
o
self
.
resize
T
o
=
resize
T
o
self
.
_counter
=
0
self
.
_counter
=
0
self
.
_dict
=
{}
self
.
_dict
=
{}
if
_IS_PY3
:
if
_IS_PY3
:
self
.
_next
_t
ime
=
itertools
.
count
(
0
).
__next__
self
.
_next
T
ime
=
itertools
.
count
(
0
).
__next__
else
:
else
:
self
.
_next
_t
ime
=
itertools
.
count
(
0
).
next
self
.
_next
T
ime
=
itertools
.
count
(
0
).
next
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
item
=
self
.
_dict
[
key
]
item
=
self
.
_dict
[
key
]
item
[
2
]
=
self
.
_next
_t
ime
()
item
[
2
]
=
self
.
_next
T
ime
()
return
item
[
1
]
return
item
[
1
]
def
__len__
(
self
):
def
__len__
(
self
):
...
@@ -45,14 +47,14 @@ class LRUCache(object):
...
@@ -45,14 +47,14 @@ class LRUCache(object):
def
__setitem__
(
self
,
key
,
value
):
def
__setitem__
(
self
,
key
,
value
):
item
=
self
.
_dict
.
get
(
key
)
item
=
self
.
_dict
.
get
(
key
)
if
item
is
None
:
if
item
is
None
:
if
len
(
self
.
_dict
)
+
1
>
self
.
max
_s
ize
:
if
len
(
self
.
_dict
)
+
1
>
self
.
max
S
ize
:
self
.
_resize
_t
o
()
self
.
_resize
T
o
()
item
=
[
key
,
value
,
self
.
_next
_t
ime
()]
item
=
[
key
,
value
,
self
.
_next
T
ime
()]
self
.
_dict
[
key
]
=
item
self
.
_dict
[
key
]
=
item
else
:
else
:
item
[
1
]
=
value
item
[
1
]
=
value
item
[
2
]
=
self
.
_next
_t
ime
()
item
[
2
]
=
self
.
_next
T
ime
()
def
__delitem__
(
self
,
key
):
def
__delitem__
(
self
,
key
):
del
self
.
_dict
[
key
]
del
self
.
_dict
[
key
]
...
@@ -73,17 +75,17 @@ class LRUCache(object):
...
@@ -73,17 +75,17 @@ class LRUCache(object):
def
keys
(
self
):
def
keys
(
self
):
return
[
x
[
0
]
for
x
in
self
.
_dict
.
values
()]
return
[
x
[
0
]
for
x
in
self
.
_dict
.
values
()]
def
_resize
_t
o
(
self
):
def
_resize
T
o
(
self
):
ordered
=
sorted
(
self
.
_dict
.
values
(),
key
=
operator
.
itemgetter
(
2
))[:
self
.
resize
_t
o
]
ordered
=
sorted
(
self
.
_dict
.
values
(),
key
=
operator
.
itemgetter
(
2
))[:
self
.
resize
T
o
]
for
i
in
ordered
:
for
i
in
ordered
:
del
self
.
_dict
[
i
[
0
]]
del
self
.
_dict
[
i
[
0
]]
def
iteritems
(
self
,
access
_t
ime
=
False
):
def
iteritems
(
self
,
access
T
ime
=
False
):
'''
'''
:param bool access
_t
ime:
:param bool access
T
ime:
If True sorts the returned items by the internal access time.
If True sorts the returned items by the internal access time.
'''
'''
if
access
_t
ime
:
if
access
T
ime
:
for
x
in
sorted
(
self
.
_dict
.
values
(),
key
=
operator
.
itemgetter
(
2
)):
for
x
in
sorted
(
self
.
_dict
.
values
(),
key
=
operator
.
itemgetter
(
2
)):
yield
x
[
0
],
x
[
1
]
yield
x
[
0
],
x
[
1
]
else
:
else
:
...
@@ -98,17 +100,20 @@ class LRUCache(object):
...
@@ -98,17 +100,20 @@ class LRUCache(object):
return
[
x
[
0
]
for
x
in
self
.
_dict
.
itervalues
()]
return
[
x
[
0
]
for
x
in
self
.
_dict
.
itervalues
()]
def
_resize
_t
o
(
self
):
def
_resize
T
o
(
self
):
ordered
=
sorted
(
self
.
_dict
.
itervalues
(),
key
=
operator
.
itemgetter
(
2
))[:
self
.
resize
_t
o
]
ordered
=
sorted
(
self
.
_dict
.
itervalues
(),
key
=
operator
.
itemgetter
(
2
))[:
self
.
resize
T
o
]
for
i
in
ordered
:
for
i
in
ordered
:
del
self
.
_dict
[
i
[
0
]]
del
self
.
_dict
[
i
[
0
]]
def
iteritems
(
self
,
access
_t
ime
=
False
):
def
iteritems
(
self
,
access
T
ime
=
False
):
'''
'''
:param bool access_time:
============= ======================================================
If True sorts the returned items by the internal access time.
**Arguments**
accessTime (bool) If True sorts the returned items by the
internal access time.
============= ======================================================
'''
'''
if
access
_t
ime
:
if
access
T
ime
:
for
x
in
sorted
(
self
.
_dict
.
itervalues
(),
key
=
operator
.
itemgetter
(
2
)):
for
x
in
sorted
(
self
.
_dict
.
itervalues
(),
key
=
operator
.
itemgetter
(
2
)):
yield
x
[
0
],
x
[
1
]
yield
x
[
0
],
x
[
1
]
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment