0

Here is the sample code

Efficiently find binary strings with low Hamming distance in large set

static inline int distance(unsigned x, unsigned y)
{
   return __builtin_popcount(x^y);
}

Is it possible to rewrite the above gcc code in python using ctypes (preferably Win/*nix compatible)?

TIA!

Community
  • 1
  • 1
est
  • 11,429
  • 14
  • 70
  • 118
  • 2
    `__builtin_*` are GCC built-in, not C functions, so I would not expect `ctypes` to be able to call them. – ephemient Nov 01 '11 at 18:43

1 Answers1

3

The gmpy library can calculate the Hamming distance between two integers. Even though it may be more general than you require, it will be faster than calling code via ctypes.

Disclaimer: I maintain gmpy.

casevh
  • 11,093
  • 1
  • 24
  • 35