Skip to content

Commit

Permalink
Simplified and perf improved (on my machine)
Browse files Browse the repository at this point in the history
  • Loading branch information
tammoippen committed Sep 4, 2017
1 parent d7c84f2 commit 79ba649
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions geohash_hilbert/_int2str.py
Expand Up @@ -61,11 +61,12 @@ def decode_int(tag, bits_per_char=6):


def _encode_int64(code):
res = []
while code > 0:
res.append(_BASE64[code & 0b111111])
code_len = (code.bit_length() + 5) // 6 # 6 bit per code point
res = ['0'] * code_len
for i in range(code_len - 1, -1, -1):
res[i] = _BASE64[code & 0b111111]
code >>= 6
return ''.join(reversed(res))
return ''.join(res)


def _decode_int64(t):
Expand All @@ -91,11 +92,14 @@ def _decode_int16(t):

def _encode_int4(code):
_BASE4 = '0123'
res = []
while code > 0:
res.append(_BASE4[code & 0b11])
code_len = (code.bit_length() + 1) // 2 # two bit per code point
res = ['0'] * code_len

for i in range(code_len - 1, -1, -1):
res[i] = _BASE4[code & 0b11]
code >>= 2
return ''.join(reversed(res))

return ''.join(res)


def _decode_int4(t):
Expand Down

0 comments on commit 79ba649

Please sign in to comment.