Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hamming weight based indexing

Tags:

People also ask

What is hamming weight used for?

The Hamming weight determines path lengths between nodes in Chord distributed hash tables. IrisCode lookups in biometric databases are typically implemented by calculating the Hamming distance to each stored record.

How is hamming weight calculated?

Hamming Weight Solution 1: Brute Force Per the constraints, all the elements in the array can be stored in a 32-bit integer and hence, to calculate the number of set bits in an integer x , we can iterate on all these 32 bits of the corresponding integer and keep a count of the number of set bits.

How do you calculate the weight of a Hamming Python?

The easiest way to get the Hamming Weight (count of bits that are set for a number) is to convert the number to its binary representation as a string using the bin-function. It will return a string like 0b1101 for the number 13. Then all that is left to do is to count the ones.


Assume we have a integer of bitsize n=4;
The problem I am describing is how you would go about indexing a number to an array position based on the Hamming weight and its value knowing the bitsize. E.g. An array with 16 elements for bitsize 4 would/could look like this:

|0|1|2|4|8|3|5|6|9|10|12|7|11|13|14|15|

Where elements are grouped by their Hamming weight(necessary) and sorted based on size(not necessary). Sorting is not necessary as long as you can take e.g. 3(0011) do some operations and get back index 5, 5(0101) -> 6 etc.

All combinations of n bits will be present and there will be no duplication. E.g. bitsize of 3 would have the array:

|0|1|2|4|3|5|6|7|

I would preferably have a solution without loops. Or any papers that discuss simillar solutions. Or finally just throw out any ides on how you could go about doing that.