Skip to content

indexing

indexing

Functions:

Name Description
absindex

Ensure's Index is a positive index, -1 == length-1

absindex

absindex(index: int | None, length: int) -> int

Ensure's Index is a positive index, -1 == length-1

Source code in hexital/utils/indexing.py
1
2
3
4
5
def absindex(index: int | None, length: int) -> int:
    """Ensure's Index is a positive index, -1 == length-1"""
    if index is None or index < -length or index >= length:
        return length - 1
    return index if index >= 0 else length + index