Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions darts/lib/utils/lru.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""Trivial LRU-Dictionary implementation
"""

from __future__ import with_statement


import sys
from threading import RLock, Lock, Condition, Thread
Expand Down Expand Up @@ -234,7 +234,7 @@ def __iter__(self):
See `iterkeys`.
"""

return self.__index.iterkeys()
return iter(self.__index.keys())

def iterkeys(self):

Expand All @@ -249,7 +249,7 @@ def iterkeys(self):
priority in any way.
"""

return self.__index.iterkeys()
return iter(self.__index.keys())

def itervalues(self):

Expand All @@ -264,7 +264,7 @@ def itervalues(self):
priority in any way.
"""

for item in self.__index.itervalues():
for item in self.__index.values():
yield item._value

def iteritems(self):
Expand All @@ -280,7 +280,7 @@ def iteritems(self):
*not* reflect the LRU priority in any way.
"""

for key, item in self.__index.iteritems():
for key, item in self.__index.items():
yield key, item._value

def __delitem__(self, key):
Expand Down Expand Up @@ -629,7 +629,7 @@ def __iter__(self):
See `iterkeys`.
"""

return self.iterkeys()
return iter(self.keys())

def iterkeys(self):

Expand All @@ -649,7 +649,7 @@ def iterkeys(self):
"""

with self.__lock:
return iter(tuple(self.__dict.iterkeys()))
return iter(tuple(self.__dict.keys()))

def itervalues(self):
"""Iterator for all values of this dictionary
Expand All @@ -668,7 +668,7 @@ def itervalues(self):
"""

with self.__lock:
return iter(tuple(self.__dict.itervalues()))
return iter(tuple(self.__dict.values()))

def iteritems(self):

Expand All @@ -688,7 +688,7 @@ def iteritems(self):
"""

with self.__lock:
return iter(tuple(self.__dict.iteritems()))
return iter(tuple(self.__dict.items()))

def __getitem__(self, key):

Expand Down Expand Up @@ -846,7 +846,7 @@ def clear(self, discard_loads=False):
self.__cache.clear()
if discard_loads:
conditions = list()
keys = tuple(self.__loading.iterkeys())
keys = tuple(self.__loading.keys())
for k in keys:
placeholder = self.__loading.pop(k)
if placeholder._state is loading:
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def clear(self, discard_loads=False):
self.__cache.clear()
if discard_loads:
conditions = list()
keys = tuple(self.__loading.iterkeys())
keys = tuple(self.__loading.keys())
for k in keys:
placeholder = self.__loading.pop(k)
if placeholder._state is loading:
Expand Down
12 changes: 6 additions & 6 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
master_doc = 'index'

# General information about the project.
project = u'dart.utils.lru'
copyright = u'2010, Deterministic Arts'
project = 'dart.utils.lru'
copyright = '2010, Deterministic Arts'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -178,8 +178,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'dartutilslru.tex', u'dart.utils.lru Documentation',
u'Deterministic Arts', 'manual'),
('index', 'dartutilslru.tex', 'dart.utils.lru Documentation',
'Deterministic Arts', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -211,6 +211,6 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'dartutilslru', u'dart.utils.lru Documentation',
[u'Deterministic Arts'], 1)
('index', 'dartutilslru', 'dart.utils.lru Documentation',
['Deterministic Arts'], 1)
]
10 changes: 5 additions & 5 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_concurrent_access(self):

iterations_per_thread = 1000
number_of_threads = 100
key_range = range(4)
key_range = list(range(4))

loads_lock = RLock()
loads = dict()
Expand Down Expand Up @@ -92,7 +92,7 @@ def reader():
with start_lock:
while not start_now:
start_condition.wait()
for k in xrange(iterations_per_thread):
for k in range(iterations_per_thread):
for i in shuffled(key_range):
answer = cache.load(i)
self.assertEqual("R(%r)" % (i,), answer)
Expand All @@ -102,7 +102,7 @@ def reader():

with start_lock:

for k in xrange(number_of_threads):
for k in range(number_of_threads):
thr = Thread(target=reader)
thr.start()

Expand All @@ -124,15 +124,15 @@ def reader():
# Make sure, that all keys have actually been requested
# at least once.

self.assertEqual(set(key_range), set(loads.iterkeys()))
self.assertEqual(set(key_range), set(loads.keys()))

# The cache has a capacity such, that it can hold all
# elements nominally ever requested by the readers. So,
# we expect, that every requested key is loaded exactly
# once (due to the cache keeping track of what it is
# currently loading).

for key,count in loads.iteritems():
for key,count in loads.items():
self.assertEqual(1, count)
self.assertTrue(key in key_range)

Expand Down