public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Ferenc Havasi <havasi@inf.u-szeged.hu>
Cc: linux-mtd@lists.infradead.org
Subject: Re: Duplication of dirent names in JFFS2 summary
Date: Fri, 19 May 2006 12:53:52 +0100	[thread overview]
Message-ID: <1148039632.3875.131.camel@pmac.infradead.org> (raw)
In-Reply-To: <1148000482.13399.42.camel@shinybook.infradead.org>

On Fri, 2006-05-19 at 02:01 +0100, David Woodhouse wrote:
> And would we benefit by using a variable-length encoding of the integers
> in the summary entries? We're far from being CPU-bound when we eat
> these, surely?

Thinking of something vaguely like UTF-8, but more optimal. Each byte
would convey seven bits of information, and the top bit would indicate
whether there's a further byte to be added.

So a number from 0-127 would be stored as-is, while numbers from
128-16383 are stored with seven bits in each of two bytes, with the top
bit of the first set and the top bit of the second clear.

This means we take only two bytes for the common node lengths -- one
byte for nodes up to 508 bytes (obviously we can shift the length >>2
before storing it since it's always a multiple of 4). 

Or should we be more ambitious and actually go for bit-packing instead
of just bytes?

unsigned char *encode_int(unsigned char *p, uint32_t val)
{
	switch (val) {
	case (1<<28) ... 0xffffffff:
		*p++ = 0x80 | ((val >> 28) & 0x7f);
	case (1<<21) ... (1<<28)-1:
		*p++ = 0x80 | ((val >> 21) & 0x7f);
	case (1<<14) ... (1<<21)-1:
		*p++ = 0x80 | ((val >> 14) & 0x7f);
	case (1<<7) ... (1<<14)-1:
		*p++ = 0x80 | ((val >> 7) & 0x7f);
	default:
		*p++ = val & 0x7f;
	}
	return p;
}

unsigned char *decode_int(unsigned char *p, uint32_t *val)
{
	uint32_t ret = 0;
	unsigned char c;

	while ((c = *p++) & 0x80) {
		ret |= c & 0x7f;
		ret <<= 7;
	}
	ret |= c;
	*val = ret;
	return p;
}


-- 
dwmw2

  reply	other threads:[~2006-05-19 11:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-19  0:44 Duplication of dirent names in JFFS2 summary David Woodhouse
2006-05-19  1:01 ` David Woodhouse
2006-05-19 11:53   ` David Woodhouse [this message]
2006-05-19 11:58     ` Artem B. Bityutskiy
2006-05-19 12:11       ` David Woodhouse
2006-05-19 12:14         ` Artem B. Bityutskiy
2006-05-19 12:31           ` David Woodhouse
2006-05-19 14:34             ` Artem B. Bityutskiy
2006-05-19 14:59               ` David Woodhouse
2006-05-19 16:41                 ` David Woodhouse
2006-05-19 16:43                   ` David Woodhouse
2006-05-19  6:05 ` Jörn Engel
2006-05-19 10:08   ` David Woodhouse
2006-05-19 11:32 ` Artem B. Bityutskiy
2006-05-19 11:57 ` Artem B. Bityutskiy
2006-05-19 12:05   ` Artem B. Bityutskiy
2006-05-19 12:23     ` David Woodhouse
2006-05-19 14:17       ` Artem B. Bityutskiy
2006-05-19 14:50         ` David Woodhouse
2006-05-19 15:07           ` Artem B. Bityutskiy
2006-05-19 15:26             ` Artem B. Bityutskiy
2006-05-19 15:33               ` David Woodhouse
2006-05-19 15:38                 ` Artem B. Bityutskiy
2006-05-19 15:43                   ` David Woodhouse
2006-05-19 15:46                     ` Artem B. Bityutskiy
2006-05-20  8:38                     ` Artem B. Bityutskiy
2006-05-20  9:08                       ` Artem B. Bityutskiy
2006-05-19 15:37             ` David Woodhouse

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=1148039632.3875.131.camel@pmac.infradead.org \
    --to=dwmw2@infradead.org \
    --cc=havasi@inf.u-szeged.hu \
    --cc=linux-mtd@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox