git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: linux@horizon.com
To: gitzilla@gmail.com
Cc: git@vger.kernel.org, linux@horizon.com
Subject: Re: A look at some alternative PACK file encodings
Date: 7 Sep 2006 04:41:58 -0400	[thread overview]
Message-ID: <20060907084158.25725.qmail@science.horizon.com> (raw)

A few notes:


Re: base-128 encodings, it's a pet peeve of mine that meny people, even
while trying to save space, waste it by allowing redundant encodings.
The optimal way, assming msbit=1 means "more", is

	0x00 -> 0		0x01 -> 1
	0x7f -> 127		0x80 0x00 -> 128
	0x80 0x7f -> 255	0x81 0x00 -> 256
	0xfe 0x7f -> 16383	0xff 0x00 -> 16384
	0xff 0x7f -> 16511	0x80 0x00 0x00 -> 16512

The decoding code can be written several ways, but try:

	c = *p++;
	x = c & 127;
	while (c & 128) {
		c = *p++;
		x = ((x + 1) << 7) + (c & 127);
	}

encoding is most easily done in reverse:

	char buf[9];
	char *p = buf+8;

	*p = x & 127;
	while (x >>= 7)
		*--p = 0x80 | (--x & 127);

	write_out(p, buf + 9 - p);


If you want to do signed offsets, the easiest way to write the code
is to convert to an unsigned with the sign bit as lsbit:

	u = (s << 1) ^ -(s < 0);

And then feed the resulting unsigned number to the functions above.
Handling the sign bit specially in the encoding is messier.


And finally, regarding qsort(), stability is not guaranteed, but glibc
actually uses a stable merge sort if it can allocate the memory.  See
http://sourceware.org/cgi-bin/cvsweb.cgi/libc/stdlib/msort.c?rev=1.21&cvsroot=glibc

This leads to the slightly annoying question of whether it's worth
writing a stable sort just to make git work a little bit better
on non-glibc platforms, when it doesn't affect most current users
personally and it still works correctly with an unstable qsort.

It might be simplest to simply lift the glibc mergesort implementation,
possibly inlining the compares for efficiency.  If you touch the code,
please (my eyes!  it hurts us!) consider fixing the brace style.

             reply	other threads:[~2006-09-07  8:42 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-07  8:41 linux [this message]
2006-09-07 17:20 ` A look at some alternative PACK file encodings Nicolas Pitre
2006-09-07 19:16   ` linux
  -- strict thread matches above, loose matches on Subject: below --
2006-09-07  9:07 linux
2006-09-07 12:57 ` Jon Smirl
2006-09-07 13:34   ` linux
2006-09-07 14:19     ` Jon Smirl
2006-09-07 15:01       ` linux
2006-09-07 14:39     ` Richard Curnow
2006-09-07 17:40       ` Junio C Hamano
2006-09-07 17:22   ` A Large Angry SCM
2006-09-07 17:32 ` Nicolas Pitre
2006-09-07 19:22   ` linux
2006-09-06 21:47 A Large Angry SCM
2006-09-06 23:23 ` Jon Smirl
2006-09-06 23:39   ` A Large Angry SCM
2006-09-06 23:56     ` Linus Torvalds
2006-09-07  0:10       ` Jon Smirl
2006-09-07  0:06         ` David Lang
2006-09-07  0:19       ` A Large Angry SCM
2006-09-07  0:45         ` Linus Torvalds
2006-09-07  0:37       ` Nicolas Pitre
2006-09-07  0:04     ` Jon Smirl
2006-09-07  5:41       ` Shawn Pearce
2006-09-07  5:34     ` Shawn Pearce
2006-09-07  0:40   ` Nicolas Pitre
2006-09-07  0:59     ` Jon Smirl
2006-09-07  2:30       ` Nicolas Pitre
2006-09-07  2:33       ` A Large Angry SCM
2006-09-07  1:11     ` Junio C Hamano
2006-09-07  2:47       ` Nicolas Pitre
2006-09-07  4:33     ` Shawn Pearce
2006-09-07  5:27       ` Junio C Hamano
2006-09-07  5:46         ` Shawn Pearce
2006-09-07 18:50           ` Junio C Hamano
2006-09-07  5:21   ` Shawn Pearce
     [not found] ` <9e4733910609061617m6783d6c4xaca2f9575e12d455@mail.gmail.com>
2006-09-07  5:39   ` A Large Angry SCM

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=20060907084158.25725.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=git@vger.kernel.org \
    --cc=gitzilla@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).