kb_incr adds a number of bytes to a kb_t variable. This is simply a
addition operator.
0x3ff == 1024 - 1
x >> 10 == x / 1024
x & 0x3ff == x % 1024
Just a clever coding trick that obfuscates the purpose of the code to
anyone not knowing power of 2 mathematics.
Regards
Henrik
maer727@sohu.com wrote:
>
> Hi, pals!
>
> I am using squid-2.5.PRE6. I am puzzled at the following function,
> (in TOOLS.c)
> void
> kb_incr(kb_t * k, size_t v)
> {
> k->bytes += v;
> k->kb += (k->bytes >> 10);
> k->bytes &= 0x3FF;
> }
>
> I think the function is to change metric from byte to k,
> but the does the following statement mean,
> k->bytes &= 0x3FF;
>
> Why should it use "AND" operation?
>
> Best regards
> George, Ma
Received on Thu Apr 18 2002 - 10:29:09 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:15:12 MST