Rev | Line | |
---|
[309] | 1 | from typing import TypeVar
|
---|
| 2 | from tudelft.utilities.immutablelist.AbstractImmutableList import AbstractImmutableList
|
---|
| 3 | from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
|
---|
| 4 | from tudelft.utilities.immutablelist.SubList import SubList
|
---|
| 5 | T=TypeVar("T")
|
---|
| 6 |
|
---|
| 7 | class PowerSet(AbstractImmutableList[ImmutableList[T]]):
|
---|
| 8 | '''
|
---|
| 9 | the power set (or powerset) of any set S is the set of all subsets of S,
|
---|
| 10 | including the empty set and S itself. The given list is assumed to be a set,
|
---|
| 11 | so without duplicates.
|
---|
| 12 |
|
---|
| 13 | @param T the element type of all lists that we receive.
|
---|
| 14 | '''
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | def __init__(self, list:ImmutableList[T] ) :
|
---|
| 18 | self._list = list
|
---|
| 19 |
|
---|
| 20 | def get(self, index:int) -> ImmutableList[T] :
|
---|
| 21 | if index >= self.size():
|
---|
| 22 | raise IndexError("Index out of bounds:" + str(index))
|
---|
| 23 | return SubList[T](self._list, index)
|
---|
| 24 |
|
---|
| 25 | def size(self)->int:
|
---|
| 26 | return 1 << self._list.size()
|
---|
| 27 |
|
---|
| 28 | def __hash__(self):
|
---|
| 29 | return 17*hash(list)
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | def __eq__(self, other):
|
---|
| 33 | return isinstance(other, self.__class__) \
|
---|
| 34 | and self._list==other._list
|
---|
Note:
See
TracBrowser
for help on using the repository browser.