source: utilitiespy/tudelft/utilities/immutablelist/AbstractPermutations.py@ 1356

Last change on this file since 1356 was 1343, checked in by wouter, 9 days ago

#413 added Permutations

File size: 1.1 KB
Line 
1from typing import TypeVar
2from tudelft.utilities.immutablelist.Permutations import Permutations
3from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
4from tudelft.utilities.immutablelist.AbstractImmutableList import AbstractImmutableList
5from _ctypes import ArgumentError
6
7
8E = TypeVar('E')
9class AbstractPermutations(AbstractImmutableList[ImmutableList[E]], Permutations[E]) :
10 '''
11 Abstract base class for Permutations. A Permutation is an ordered sublist of
12 a list, possibly with repeated elements.
13
14 @param <E> type of the elements
15
16 '''
17
18 def __init__(self, lst: ImmutableList[E] , n:int):
19 '''
20 all permutations of a given list, drawing n items from the list
21
22 @param lst list to be permuted
23 @param n the number of items to draw from the list. Must be between 0
24 and size of list.
25 '''
26 if n < 0:
27 raise ArgumentError("n<0")
28 if lst.size().bit_length() > 31:
29 raise ArgumentError(\
30 "excessive list size detected for starting a permutation"\
31 + str(lst.size()))
32 # protected, not private vars
33 self._drawlist:ImmutableList[E] = lst
34 self._drawlistsize:int = lst.size()
35 self._drawsize:int = n
Note: See TracBrowser for help on using the repository browser.