Rev | Line | |
---|
[1342] | 1 | from typing import TypeVar
|
---|
| 2 | from tudelft.utilities.immutablelist.Permutations import Permutations
|
---|
| 3 | from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
|
---|
| 4 | from tudelft.utilities.immutablelist.AbstractImmutableList import AbstractImmutableList
|
---|
| 5 | from _ctypes import ArgumentError
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | E = TypeVar('E')
|
---|
| 9 | class 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")
|
---|
[1343] | 28 | if lst.size().bit_length() > 31:
|
---|
[1342] | 29 | raise ArgumentError(\
|
---|
| 30 | "excessive list size detected for starting a permutation"\
|
---|
[1343] | 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.