Last change
on this file since 1342 was 1342, checked in by wouter, 6 days ago |
#413 added Permutations-related classes. Pending tests
|
File size:
1.1 KB
|
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")
|
---|
| 28 | if len(lst).bit_Length() > 31:
|
---|
| 29 | raise ArgumentError(\
|
---|
| 30 | "excessive list size detected for starting a permutation"\
|
---|
| 31 | + len(list))
|
---|
| 32 | self.__drawlist:ImmutableList[E] = lst
|
---|
| 33 | self.__drawlistsize:int = len(lst)
|
---|
| 34 | self.__drawsize:int = n
|
---|
Note:
See
TracBrowser
for help on using the repository browser.