djbdns
[Top] [All Lists]

Re: djbdns-1.05-epoll + speedup patch

To: djbdns Mailing List <dns@list.cr.yp.to>
Subject: Re: djbdns-1.05-epoll + speedup patch
From: "Matthew R. Dempsky" <mrd@alkemio.org>
Date: Mon, 5 Mar 2007 08:24:37 -0600
Delivered-to: sp-com-lists@consult.net
Delivered-to: gmail-djbdns@securepoint.com
Delivered-to: sp.com.list@gmail.com
Delivered-to: mailing list dns@list.cr.yp.to
In-reply-to: <20070304161657.qrytvzoi37inmj45@m.safari.iki.fi>
Mail-followup-to: djbdns Mailing List <dns@list.cr.yp.to>
Mailing-list: contact dns-help@list.cr.yp.to; run by ezmlm
References: <20070116171333.GA5674@m.safari.iki.fi> <20070222122129.GE3982@m.safari.iki.fi> <20070222162522.GG3982@m.safari.iki.fi> <20070304161657.qrytvzoi37inmj45@m.safari.iki.fi>
On Sun, Mar 04, 2007 at 06:16:57PM +0200, Sami Farin wrote:
> +static inline void dns_sortip(char *s,unsigned int n)
> +{
> +  int i;
> +  unsigned int rnd;
> +  char tmp[4];
> +
> +  n >>= 2;
> +  for (i = n - 1; i > 0; i--) {
> +    rnd = dns_random() % n;
> +    byte_copy(tmp,4,s + (i << 2));
> +    byte_copy(s + (i << 2),4,s + (rnd << 2));
> +    byte_copy(s + (rnd << 2),4,tmp);
> +  }
> +}

Beware this does not generate the same distribution as:

> -void dns_sortip(char *s,unsigned int n)
> -{
> -  unsigned int i;
> -  char tmp[4];
> -
> -  n >>= 2;
> -  while (n > 1) {
> -    i = dns_random(n);
> -    --n;
> -    byte_copy(tmp,4,s + (i << 2));
> -    byte_copy(s + (i << 2),4,s + (n << 2));
> -    byte_copy(s + (n << 2),4,tmp);
> -  }
> -}

<Prev in Thread] Current Thread [Next in Thread>