Re: [B.A.T.M.A.N.] BATMAN routing

Sven Eckelmann
2011-04-03T21:25:55Z

[-- Attachment #1: Type: Text/Plain, Size: 1124 bytes --]

hlabishi kobo wrote:
> int weighted_bit_packet_count(TYPE_OF_WORD *seq_bits)
> {
> int i,check, count = 0;
> TYPE_OF_WORD word;
>
> for (i = 0; i < NUM_WORDS; i++) {
> word = seq_bits[i];
> int j = WORD_BIT_SIZE, k = 1;
>
> while (j > 0 && k <= 32){

it is wrong to assume that unsigned long is 32 bit long.

> check = (word & (1 << j)) >> j;
> if (check == 1)
> count += k;
> j--;
> k++;

I would doubt that it is correct to give every set bit the same weight when
they have the the distance of sizeof(unsigned long)*8. And I cannot find a
good reason why an "old" unsigned long should get the same weights as the
"newest" unsigned long - at least not when the actual weights should be
reduced for "older" bits in a single unsigned long and the overall weights
should be monotonic decreasing with the age. And using WORD_BIT_SIZE for j is
like assuming that we only have a single unsigned long in seq_bits... which is
not true for many architectures.

And the code is overly complicated without any good reason.

Kind regards,
Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]