Skip to content

Commit 94a069d

Browse files
committed
-
1 parent 5d60600 commit 94a069d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

source_py3/python_toolbox/combi/perm_space.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class PermSpace(sequence_tools.CuteSequenceMixin, collections.Sequence,
9797
- Partial: A perm space can be partial, in which case not all elements
9898
are used in perms. E.g. you can have a perm space of a sequence of
9999
length 5 but with `n_elements=3`, so every perm will have only 3 items.
100-
To make one, pass a number as the argument `n_elements`.
100+
(These are usually called "k-permutations" in math-land.) To make one,
101+
pass a number as the argument `n_elements`.
101102
- Combination: If you pass in `is_combination=True` or use the subclass
102103
`CombSpace`, then you'll have a space of combinations (combs) instead of
103104
perms. Combs are like perms except there's no order to the elements.
@@ -162,22 +163,21 @@ def __init__(self, iterable_or_length, domain=None, n_elements=None,
162163
self.sequence_length = len(self.sequence)
163164
if not self.is_rapplied:
164165
self.sequence = sequence_tools.CuteRange(self.sequence_length)
165-
166-
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)
175-
# Can implement this later by calculating the actual length.
176-
raise NotImplementedError
177166

178167
# #
179168
### Finished figuring out sequence and whether space is rapplied. #####
180169

170+
self.repeating_items = sortedcontainers.SortedDict()
171+
if self.is_rapplied:
172+
sequence_set = set(self.sequence)
173+
for i, item in enumerate(self.sequence):
174+
if item in sequence_set:
175+
if item not in self.repeating_items:
176+
self.repeating_items[item] = \
177+
sortedcontainers.SortedSet()
178+
self.repeating_items[item].add(i)
179+
self.is_recurrent = bool(self.repeating_items)
180+
181181
### Figuring out number of elements: ##################################
182182
# #
183183

0 commit comments

Comments
 (0)