try hyperloglog and find its only good at superbig
This commit is contained in:
23
hyperloglog.py
Normal file
23
hyperloglog.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import sys
|
||||
|
||||
def main(args):
|
||||
if not args:
|
||||
args = [str(chr(c)) for c in range(ord('a'), ord('z'))]
|
||||
|
||||
bucket = 0
|
||||
|
||||
for arg in args:
|
||||
v = '{:b}'.format(hash(arg)).lstrip('-')
|
||||
i = 63 - len(v)
|
||||
for c in v:
|
||||
if c != '0':
|
||||
break
|
||||
i += 1
|
||||
if i > bucket:
|
||||
bucket = i
|
||||
print(f'{i} <= {v} <= {arg}')
|
||||
|
||||
print(f'result={2**bucket}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
Reference in New Issue
Block a user