from typing import TypeVar from tudelft.utilities.immutablelist.Permutations import Permutations from tudelft.utilities.immutablelist.ImmutableList import ImmutableList from tudelft.utilities.immutablelist.AbstractImmutableList import AbstractImmutableList from _ctypes import ArgumentError E = TypeVar('E') class AbstractPermutations(AbstractImmutableList[ImmutableList[E]], Permutations[E]) : ''' Abstract base class for Permutations. A Permutation is an ordered sublist of a list, possibly with repeated elements. @param type of the elements ''' def __init__(self, lst: ImmutableList[E] , n:int): ''' all permutations of a given list, drawing n items from the list @param lst list to be permuted @param n the number of items to draw from the list. Must be between 0 and size of list. ''' if n < 0: raise ArgumentError("n<0") if lst.size().bit_length() > 31: raise ArgumentError(\ "excessive list size detected for starting a permutation"\ + str(lst.size())) # protected, not private vars self._drawlist:ImmutableList[E] = lst self._drawlistsize:int = lst.size() self._drawsize:int = n