From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Eriksen <s022018@student.dtu.dk>, git@vger.kernel.org
Subject: Re: Distribution of longest common hash prefixes
Date: Mon, 02 Apr 2007 09:29:20 -0700 [thread overview]
Message-ID: <86bqi6kae7.fsf@blue.stonehenge.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0704020817250.6730@woody.linux-foundation.org> (Linus Torvalds's message of "Mon, 2 Apr 2007 08:20:51 -0700 (PDT)")
>>>>> "Linus" == Linus Torvalds <torvalds@linux-foundation.org> writes:
Linus> On Mon, 2 Apr 2007, Peter Eriksen wrote:
Linus> #include <stdio.h>
Linus> #include <string.h>
Linus> int h2d(char c)
Linus> {
Linus> if ('a' <= c && c <= 'f')
Linus> return c-'a'+10;
Linus> else
Linus> return c-'0';
Linus> }
Linus> int lcprefix(char *a, char *b)
Linus> {
Linus> int bits = 0;
Linus> unsigned n1, n2;
Linus> while (*a == *b) {
Linus> bits += 4;
Linus> a++;
Linus> b++;
Linus> }
Linus> n1 = h2d(*a);
Linus> n2 = h2d(*b);
Linus> /* Would make more sense to start from bit 0.. */
Linus> while ((n1 & 8) == (n2 & 8)) {
Linus> bits++;
Linus> n1 <<= 1;
Linus> n2 <<= 1;
Linus> }
Linus> return bits;
Linus> }
Linus> int main(int argc, char **argv)
Linus> {
Linus> FILE *fp;
Linus> char old[41];
Linus> char cur[41];
Linus> int lcp = 0;
Linus> int table[64];
Linus> int i;
Linus> memset(table, 0, 64*sizeof(int));
Linus> memset(old, '0', 40);
Linus> old[40] = '\0';
Linus> fp = fopen(argv[1], "r");
Linus> fscanf(fp, "%s\n", cur);
Linus> if (lcp < lcprefix(old, cur)) {
Linus> lcp = lcprefix(old, cur);
Linus> }
Linus> table[lcp]++;
Linus> while (fscanf(fp, "%s\n", cur) != EOF) {
Linus> int newlcp = lcprefix(old, cur);
Linus> table[newlcp]++;
Linus> if (lcp < newlcp) {
Linus> printf("%s\n%s\n", old, cur);
Linus> lcp = newlcp;
Linus> printf("lcprefix = %d\n", newlcp);
Linus> }
Linus> memcpy(old, cur, 40);
Linus> }
Linus> for(i = 0; i < 64; i++) {
Linus> printf("%2d: %2d\n", i, table[i]);
Linus> }
Linus> return 0;
Linus> }
I don't have access to the linux-2.6 kernel, but on git.git at
d8b6a1a10b93666246984a50d64a163e71163aeb I get this:
$ git-rev-list --objects HEAD | sort | perl -lne '
substr($_, 40) = "";
($p ^ $_) =~ /^(\0*)/;
$count[length $1]++;
$p = $_;
END { print "$_: $count[$_]" for 0..$#count }
'
0: 16
1: 240
2: 3839
3: 24458
4: 8275
5: 619
6: 45
7:
8: 1
Yeay Perl. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
next prev parent reply other threads:[~2007-04-02 16:29 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-02 14:58 Distribution of longest common hash prefixes Peter Eriksen
2007-04-02 15:20 ` Linus Torvalds
2007-04-02 16:29 ` Randal L. Schwartz [this message]
2007-04-02 17:00 ` Linus Torvalds
2007-04-02 17:17 ` Randal L. Schwartz
2007-04-02 17:33 ` Randal L. Schwartz
2007-04-03 17:04 ` James Cloos
2007-04-03 17:11 ` Randal L. Schwartz
2007-04-03 17:21 ` Shawn O. Pearce
2007-04-03 17:50 ` Linus Torvalds
2007-04-03 18:22 ` Junio C Hamano
2007-04-03 19:27 ` Linus Torvalds
2007-04-03 19:34 ` Nicolas Pitre
2007-04-03 20:25 ` Junio C Hamano
2007-04-03 20:39 ` Nicolas Pitre
2007-04-03 23:08 ` Olivier Galibert
2007-04-03 23:22 ` Linus Torvalds
2007-04-04 21:03 ` James Cloos
2007-04-02 17:18 ` James Cloos
2007-04-02 15:28 ` Peter Eriksen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86bqi6kae7.fsf@blue.stonehenge.com \
--to=merlyn@stonehenge.com \
--cc=git@vger.kernel.org \
--cc=s022018@student.dtu.dk \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.