Check is the mapping is valid. Args: mapping: an iterable of integer. n: define the input domain as [0, n-1]. Note that the mapping can be under-complete, that is, it can only contain a subset of the integers on [0, n-1]. repetition: if True repetition are allowed (the fun
(mapping, n, repetition)
| 50 | |
| 51 | |
| 52 | def _check_within_range(mapping, n, repetition): |
| 53 | """Check is the mapping is valid. |
| 54 | |
| 55 | Args: |
| 56 | mapping: an iterable of integer. |
| 57 | n: define the input domain as [0, n-1]. Note that the mapping can be |
| 58 | under-complete, that is, it can only contain a subset of the integers on |
| 59 | [0, n-1]. |
| 60 | repetition: if True repetition are allowed (the function is surjective) |
| 61 | otherwise repetition are not allowed (the function is injective). |
| 62 | Raises: |
| 63 | ValueError: if the mapping is out of range ot if repetition is False and |
| 64 | the mapping has some repetition. |
| 65 | """ |
| 66 | for i in mapping: |
| 67 | if not 0 <= i < n: |
| 68 | raise ValueError("Out of [0, {}[ range: {}".format(n, i)) |
| 69 | if not repetition and len(set(mapping)) != len(mapping): |
| 70 | raise ValueError("Found repetition in mapping: {}".format(mapping)) |
| 71 | |
| 72 | |
| 73 | class SubGraphView(object): |
no test coverage detected