Skip to content

Commit e01e036

Browse files
committed
-
1 parent 43524fb commit e01e036

File tree

10 files changed

+2792
-3028
lines changed

10 files changed

+2792
-3028
lines changed

source_py2/python_toolbox/third_party/sortedcontainers/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,20 @@
3535
pre-build and distribute custom extensions. Performance is a feature and
3636
testing has 100% coverage with unit tests and hours of stress.
3737
38-
:copyright: (c) 2014 by Grant Jenks.
38+
:copyright: (c) 2015 by Grant Jenks.
3939
:license: Apache 2.0, see LICENSE for more details.
4040
4141
"""
4242

4343
__title__ = 'sortedcontainers'
44-
__version__ = '0.9.5'
45-
__build__ = 0x000905
44+
__version__ = '1.4.4'
45+
__build__ = 0x010404
4646
__author__ = 'Grant Jenks'
4747
__license__ = 'Apache 2.0'
48-
__copyright__ = 'Copyright 2014 Grant Jenks'
48+
__copyright__ = 'Copyright 2015 Grant Jenks'
4949

50-
from .sortedlist import SortedList
50+
from .sortedlist import SortedList, SortedListWithKey
5151
from .sortedset import SortedSet
5252
from .sorteddict import SortedDict
53-
from .sortedlistwithkey import SortedListWithKey
5453

5554
__all__ = ['SortedList', 'SortedSet', 'SortedDict', 'SortedListWithKey']

source_py2/python_toolbox/third_party/sortedcontainers/sorteddict.py

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Sorted dict implementation.
44

55
from .sortedset import SortedSet
6-
from .sortedlist import SortedList, recursive_repr
7-
from .sortedlistwithkey import SortedListWithKey
6+
from .sortedlist import SortedList, recursive_repr, SortedListWithKey
87
from collections import Set, Sequence
98
from collections import KeysView as AbstractKeysView
109
from collections import ValuesView as AbstractValuesView
@@ -134,7 +133,7 @@ def __init__(self, *args, **kwargs):
134133
self._pop = _dict.pop
135134
self._setdefault = _dict.setdefault
136135
self._setitem = _dict.__setitem__
137-
self._update = _dict.update
136+
self._dict_update = _dict.update
138137

139138
# Cache function pointers to SortedList methods.
140139

@@ -148,15 +147,18 @@ def __init__(self, *args, **kwargs):
148147
self._list_pop = _list.pop
149148
self._list_remove = _list.remove
150149
self._list_update = _list.update
150+
self.irange = _list.irange
151+
self.islice = _list.islice
151152

152153
if self._key is not None:
153154
self.bisect_key_left = _list.bisect_key_left
154155
self.bisect_key_right = _list.bisect_key_right
155156
self.bisect_key = _list.bisect_key
157+
self.irange_key = _list.irange_key
156158

157159
self.iloc = _IlocWrapper(self)
158160

159-
self.update(*args, **kwargs)
161+
self._update(*args, **kwargs)
160162

161163
def clear(self):
162164
"""Remove all elements from the dictionary."""
@@ -172,12 +174,20 @@ def __delitem__(self, key):
172174
self._list_remove(key)
173175

174176
def __iter__(self):
175-
"""Create an iterator over the sorted keys of the dictionary."""
177+
"""
178+
Return an iterator over the sorted keys of the dictionary.
179+
180+
Iterating the Mapping while adding or deleting keys may raise a
181+
`RuntimeError` or fail to iterate over all entries.
182+
"""
176183
return iter(self._list)
177184

178185
def __reversed__(self):
179186
"""
180-
Create a reversed iterator over the sorted keys of the dictionary.
187+
Return a reversed iterator over the sorted keys of the dictionary.
188+
189+
Iterating the Mapping while adding or deleting keys may raise a
190+
`RuntimeError` or fail to iterate over all entries.
181191
"""
182192
return reversed(self._list)
183193

@@ -189,7 +199,7 @@ def __setitem__(self, key, value):
189199

190200
def copy(self):
191201
"""Return a shallow copy of the sorted dictionary."""
192-
return self.__class__(self._key, self._load, self.iteritems())
202+
return self.__class__(self._key, self._load, self._iteritems())
193203

194204
__copy__ = copy
195205

@@ -205,7 +215,7 @@ def items(self):
205215
"""
206216
Return a list of the dictionary's items (``(key, value)`` pairs).
207217
"""
208-
return list(self.iteritems())
218+
return list(self._iteritems())
209219
else:
210220
def items(self):
211221
"""
@@ -216,9 +226,16 @@ def items(self):
216226
return ItemsView(self)
217227

218228
def iteritems(self):
219-
"""Return an iterable over the items (``(key, value)`` pairs)."""
229+
"""
230+
Return an iterator over the items (``(key, value)`` pairs).
231+
232+
Iterating the Mapping while adding or deleting keys may raise a
233+
`RuntimeError` or fail to iterate over all entries.
234+
"""
220235
return iter((key, self[key]) for key in self._list)
221236

237+
_iteritems = iteritems
238+
222239
if hexversion < 0x03000000:
223240
def keys(self):
224241
"""Return a SortedSet of the dictionary's keys."""
@@ -233,13 +250,18 @@ def keys(self):
233250
return KeysView(self)
234251

235252
def iterkeys(self):
236-
"""Return an iterable over the keys of the dictionary."""
253+
"""
254+
Return an iterator over the sorted keys of the Mapping.
255+
256+
Iterating the Mapping while adding or deleting keys may raise a
257+
`RuntimeError` or fail to iterate over all entries.
258+
"""
237259
return iter(self._list)
238260

239261
if hexversion < 0x03000000:
240262
def values(self):
241263
"""Return a list of the dictionary's values."""
242-
return list(self.itervalues())
264+
return list(self._itervalues())
243265
else:
244266
def values(self):
245267
"""
@@ -250,9 +272,16 @@ def values(self):
250272
return ValuesView(self)
251273

252274
def itervalues(self):
253-
"""Return an iterable over the values of the dictionary."""
275+
"""
276+
Return an iterator over the values of the Mapping.
277+
278+
Iterating the Mapping while adding or deleting keys may raise a
279+
`RuntimeError` or fail to iterate over all entries.
280+
"""
254281
return iter(self[key] for key in self._list)
255282

283+
_itervalues = itervalues
284+
256285
def pop(self, key, default=_NotGiven):
257286
"""
258287
If *key* is in the dictionary, remove it and return its value,
@@ -309,7 +338,7 @@ def update(self, *args, **kwargs):
309338
those key/value pairs: ``d.update(red=1, blue=2)``.
310339
"""
311340
if not len(self):
312-
self._update(*args, **kwargs)
341+
self._dict_update(*args, **kwargs)
313342
self._list_update(self._iter())
314343
return
315344

@@ -319,13 +348,15 @@ def update(self, *args, **kwargs):
319348
pairs = dict(*args, **kwargs)
320349

321350
if (10 * len(pairs)) > len(self):
322-
self._update(pairs)
351+
self._dict_update(pairs)
323352
self._list_clear()
324353
self._list_update(self._iter())
325354
else:
326355
for key in pairs:
327356
self[key] = pairs[key]
328357

358+
_update = update
359+
329360
@not26
330361
def viewkeys(self):
331362
"""
@@ -357,7 +388,7 @@ def viewitems(self):
357388
return ItemsView(self)
358389

359390
def __reduce__(self):
360-
return (self.__class__, (self._key, self._load, list(self.iteritems())))
391+
return (self.__class__, (self._key, self._load, list(self._iteritems())))
361392

362393
@recursive_repr
363394
def __repr__(self):
@@ -413,7 +444,7 @@ def __iter__(self):
413444
over in their sorted order.
414445
415446
Iterating views while adding or deleting entries in the dictionary may
416-
raise a RuntimeError or fail to iterate over all entries.
447+
raise a `RuntimeError` or fail to iterate over all entries.
417448
"""
418449
return iter(self._list)
419450
def __getitem__(self, index):
@@ -512,7 +543,7 @@ def __len__(self):
512543
return len(self._dict)
513544
def __contains__(self, value):
514545
"""
515-
Return True if and only if *value* is on the underlying dictionary's
546+
Return True if and only if *value* is in the underlying Mapping's
516547
values.
517548
"""
518549
return value in self._view
@@ -565,7 +596,7 @@ def count(self, value):
565596
else:
566597
def count(self, value):
567598
"""Return the number of occurrences of *value* in self."""
568-
return sum(1 for val in _dict.values() if val == value)
599+
return sum(1 for val in self._dict.values() if val == value)
569600
def __lt__(self, that):
570601
raise TypeError
571602
def __gt__(self, that):
@@ -629,7 +660,7 @@ def __iter__(self):
629660
over in their sorted order.
630661
631662
Iterating views while adding or deleting entries in the dictionary may
632-
raise a RuntimeError or fail to iterate over all entries.
663+
raise a `RuntimeError` or fail to iterate over all entries.
633664
"""
634665
_dict = self._dict
635666
return iter((key, _dict[key]) for key in self._list)

0 commit comments

Comments
 (0)