[SciPy-User] Smart Hashing of Integer Numbers

Lorenzo Isella lorenzo.isella at gmail.com
Thu Sep 24 08:17:08 EDT 2009


Dear All,
This is my problem: I have a couple of integer numbers (which are 
entries of a numpy array) and I would like to combine them unambiguously 
into a single (possibly short) integer number.
There are two requirements
(1) then function f(A,B)=C must be injective
(2) it would be very pleasant to be able to decompose unambiguously C 
into A and B.

I can skip condition (2) if nothing easy to implement comes to mind.
I tried something like hash((A,B)), which certainly respects (1), but 
the result can be a 19-digit long integer, which may not be the easiest 
thing to read on certain platforms.
An example taken from some of my data:

In [1]: hash((1159,9))
Out[1]: 3712118181786491231

What I need is an algorithm which does not output huge integer numbers 
unless the numbers to combine are large themselves.
Any idea is appreciated (even how to simply juxtapose A and B, like 
A=1159 and B =9 ---> C=11599 if there is nothing better).
Many thanks

Lorenzo




More information about the SciPy-User mailing list