ich suche eine minimal perfect hash Funktion.
Wenn jemand zufällig was dazu weiß bitte posten

Code: Alles auswählen
def hash_booleans(value):
hash = int(value)
if hash < 0 or hash > 1:
raise Exception("{} is not hashable".format(value))
return hash
hash_booleans(True)
> 1
hash_booleans(False)
> 0
hash_booleans(1)
> 1
hash_booleans(2)
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-19-872544668d15> in <module>()
----> 1 hash_booleans(2)
<ipython-input-15-24fbe305ed6d> in hash_booleans(value)
2 hash = int(value)
3 if hash < 0 or hash > 1:
----> 4 raise Exception("{} is not hashable".format(value))
5 return hash
Code: Alles auswählen
def hash_int(i):
return i
Code: Alles auswählen
def hash_int(i):
return -2*i-1 if i < 0 else 2*i