Created
September 10, 2022 00:54
-
-
Save nascheme/d04e6d63cfbd3e4614ca0e173b961de4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _str_to_int_inner(s): | |
DIGLIM = 2048 | |
w5pow = {} | |
w = len(s) | |
while w >= DIGLIM: | |
w2 = w >> 1 | |
if w & 1: | |
w5pow[w2 + 1] = None | |
w5pow[w2] = None | |
w = w2 | |
if w5pow: | |
it = reversed(w5pow) | |
w = next(it) | |
w5pow[w] = 5 ** w | |
for w in it: | |
if w - 1 in w5pow: | |
val = w5pow[w - 1] * 5 | |
else: | |
w2 = w >> 1 | |
val = w5pow[w2] * w5pow[w - w2] | |
w5pow[w] = val | |
def inner(a, b): | |
if b - a <= DIGLIM: | |
return int(s[a:b]) | |
split = (b - a) >> 1 | |
x = (inner(a, b - split) * w5pow[split]) << split | |
y = inner(b - split, b) | |
return x + y | |
return inner(0, len(s)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment