Re:Re: Puzzled at kb_incr in squid-2.5.PRE6.

From: <maer727@dont-contact.us>
Date: Fri, 19 Apr 2002 15:15:19 +0800 (CST)

Thanks, Henrik pal!

You have clarified all my doubts. :-)

Best regards,
George Ma

----- Original Message -----
From: Henrik Nordstrom
To: maer727@sohu.com
Cc: squid-dev@squid-cache.org
Subject: Re: Puzzled at kb_incr in squid-2.5.PRE6.
Sent: Thu Apr 18 23:53:51 CST 2002

> 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 Fri Apr 19 2002 - 01:15:44 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:15:13 MST