Rolling Hash
Calculates a hash of all substrings so that it can be compared in .
__init__
Calculates the hash of all substrings.
Arguments
S: str: string to calculate hashes
Complexities
- time:
- space:
where represents the length of the string S.
add
Concatenates two hashes of strings.
Arguments
hash1: tuple[int, int]: hash of the first stringhash2: tuple[int, int]: hash of the second string
Returns
tuple[int, int]: hash of the concatenated string
Complexities
__getitem__
Returns the hash of the substring .
Arguments
l: int: left indexr: int: right index
Returns
tuple[int, int]: hash of the substring
Complexities
__setitem__
Changes the character at index i to c.
Arguments
i: int: index to changec: str: character to change
