Skip to content

Commit 5d60600

Browse files
committed
-
1 parent 3e03c9d commit 5d60600

File tree

8 files changed

+2901
-4
lines changed

8 files changed

+2901
-4
lines changed

source_py3/python_toolbox/combi/perm_space.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@
1010
import numbers
1111

1212
from python_toolbox import misc_tools
13-
from python_toolbox import dict_tools
1413
from python_toolbox import nifty_collections
1514
from python_toolbox import sequence_tools
1615
from python_toolbox import caching
1716
import python_toolbox.arguments_profiling
18-
1917
from python_toolbox import math_tools
2018
from python_toolbox import sequence_tools
2119
from python_toolbox import cute_iter_tools
2220
from python_toolbox import nifty_collections
2321
from python_toolbox import dict_tools
22+
from python_toolbox.third_party import sortedcontainers
23+
from python_toolbox import misc_tools
2424

2525
from . import misc
26-
from python_toolbox import misc_tools
2726

2827
infinity = float('inf')
2928

@@ -165,7 +164,14 @@ def __init__(self, iterable_or_length, domain=None, n_elements=None,
165164
self.sequence = sequence_tools.CuteRange(self.sequence_length)
166165

167166

168-
if self.is_rapplied and (len(set(self.sequence)) < len(self.sequence)):
167+
if self.is_rapplied:
168+
self.repeating_elements = sortedcontainers.SortedDict()
169+
sequence_set = set()
170+
for item in self.sequence:
171+
if item in sequence_set:
172+
173+
self.repeating_elements.setdefault(item,)
174+
sequence_set.add(item)
169175
# Can implement this later by calculating the actual length.
170176
raise NotImplementedError
171177

@@ -502,6 +508,10 @@ def __getitem__(self, i):
502508
return self.perm_type(i, self)
503509

504510

511+
enumerated_sequence = caching.CachedProperty(
512+
lambda self: tuple(enumerate(self.sequence))
513+
)
514+
505515
n_unused_elements = caching.CachedProperty(
506516
lambda self: self.sequence_length - self.n_elements,
507517
'''In partial perm spaces, number of elements that aren't used.'''

source_py3/python_toolbox/nifty_collections/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .lazy_tuple import LazyTuple
1111
from .frozen_dict import FrozenDict
1212
from .frozen_counter import FrozenCounter
13+
from .default_sorted_dict import DefaultSortedDict
1314

1415
from .emitting_ordered_set import EmittingOrderedSet
1516
from .emitting_weak_key_default_dict import EmittingWeakKeyDefaultDict
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2009-2014 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
import collections
5+
6+
from python_toolbox.third_party import sortedcontainers
7+
8+
9+
class DefaultSortedDict(sortedcontainers.SortedDict):
10+
11+
def __init__(self, default_factory, *args, **kwargs):
12+
assert isinstance(default_factory, collections.Callable)
13+
self.default_factory = default_factory
14+
sortedcontainers.SortedDict.__init__(self, *args, **kwargs)
15+
16+
def copy(self):
17+
""" D.copy() -> a shallow copy of D. """
18+
return type(self)(self.default_factory, self.items())
19+
20+
def __getitem__(self, key):
21+
try:
22+
return self._dict[key]
23+
except KeyError:
24+
return self.default_factory()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
sortedcontainers Sorted Container Types Library
5+
===============================================
6+
7+
SortedContainers is an Apache2 licensed containers library, written in
8+
pure-Python, and fast as C-extensions.
9+
10+
Python's standard library is great until you need a sorted container type. Many
11+
will attest that you can get really far without one, but the moment you
12+
**really need** a sorted list, dict, or set, you're faced with a dozen
13+
different implementations, most using C-extensions without great documentation
14+
and benchmarking.
15+
16+
Things shouldn't be this way. Not in Python.
17+
18+
::
19+
20+
>>> from sortedcontainers import SortedList, SortedDict, SortedSet
21+
>>> sl = SortedList(xrange(10000000))
22+
>>> 1234567 in sl
23+
True
24+
>>> sl[7654321]
25+
7654321
26+
>>> sl.add(1234567)
27+
>>> sl.count(1234567)
28+
2
29+
>>> sl *= 3
30+
>>> len(sl)
31+
30000003
32+
33+
SortedContainers takes all of the work out of Python sorted types - making your
34+
deployment and use of Python easy. There's no need to install a C compiler or
35+
pre-build and distribute custom extensions. Performance is a feature and
36+
testing has 100% coverage with unit tests and hours of stress.
37+
38+
:copyright: (c) 2014 by Grant Jenks.
39+
:license: Apache 2.0, see LICENSE for more details.
40+
41+
"""
42+
43+
__title__ = 'sortedcontainers'
44+
__version__ = '0.9.1'
45+
__build__ = 0x000901
46+
__author__ = 'Grant Jenks'
47+
__license__ = 'Apache 2.0'
48+
__copyright__ = 'Copyright 2014 Grant Jenks'
49+
50+
from .sortedlist import SortedList
51+
from .sortedset import SortedSet
52+
from .sorteddict import SortedDict
53+
from .sortedlistwithkey import SortedListWithKey
54+
55+
__all__ = [SortedList, SortedSet, SortedDict, SortedListWithKey]

0 commit comments

Comments
 (0)