All of lore.kernel.org
 help / color / mirror / Atom feed
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 10:17:12 -0700	[thread overview]
Message-ID: <86y7laitlz.fsf@blue.stonehenge.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0704020938470.6730@woody.linux-foundation.org> (Linus Torvalds's message of "Mon, 2 Apr 2007 10:00:22 -0700 (PDT)")

>>>>> "Linus" == Linus Torvalds <torvalds@linux-foundation.org> writes:

Linus> No yay yet.. That counts hex digits, not bits.

I thought the goal was to figure out how long (on the average) you had to give
a SHA1 to be "unique".

But even that's wrong, because of the following:

CAFEFEED357
DEADBEEF123
DEADBEEF456
DEADBEEF467
DEADBEEF478

for that sequence, I'd count 0, 8, 9, 9 when in fact, it should be 8, 9, 9, 9.
It's not the items in common with the previous value... it's the longer of the
items in common with the string on either side.  The easiest way for that
would be to use a 3-item window:

git-rev-list --objects HEAD | sort | perl -lne '
  substr($_, 40) = "";
  if (defined $p) {
    ($p ^ $_) =~ /^(\0*)/;
    $common = length $1;
    if (defined $pcommon) {
      $count[$pcommon > $common ? $pcommon : $common]++;
    }
  }
  $p = $_;
  $pcommon = $common;
  END { print "$_: $count[$_]" for 0..$#count }
'

this also fixes the bug where I compare the first line to nothing.
With this, I get (on git.git):

    0: 
    1: 
    2: 6
    3: 21153
    4: 15008
    5: 1232
    6: 90
    7: 
    8: 2

which now makes sense.  There are 2 items that need 9 hex chars
to be unique.

-- 
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!

  reply	other threads:[~2007-04-02 17:17 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
2007-04-02 17:00     ` Linus Torvalds
2007-04-02 17:17       ` Randal L. Schwartz [this message]
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=86y7laitlz.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.