Re: [Tux3] [PATCH] Make sure ileaf offsets are in non-descending order

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Daniel Phillips
Date: Tuesday, September 2, 2008 - 2:27 am

On Monday 01 September 2008 23:56, Conrad Meyer wrote:

Your negative for loop is stylish.  Let's try crunching down the loop
body a little:

int isinorder(BTREE, struct ileaf *leaf)
{
	u16 *dict = (void *)leaf + btree->sb->blocksize;
	for (int i = 0, offset = 0, limit; i > -leaf->count; i--, offset = limit)
		if ((limit = dict[i]) < offset)
			return 0;
	return 1;
}

Wow, it compresses nicely :-)

It is still your nice clear and correct algorithm, just poked a little.
You can integrate it with the existing (lame) check like this:

int ileaf_check(BTREE, struct ileaf *leaf)
{
	char *why;
	why = "not an inode table leaf";
	if (leaf->magic != 0x90de)
		goto eek;
	why = "dict out of order";
	if (!isinorder(btree, leaf))
		goto eek;
	return 0;
eek:
	printf("%s!\n", why);
	return -1;
}

_______________________________________________
Tux3 mailing list
Tux3@tux3.org
http://tux3.org/cgi-bin/mailman/listinfo/tux3
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [Tux3] [PATCH] Make sure ileaf offsets are in non-desc ..., Daniel Phillips, (Tue Sep 2, 2:27 am)
[Tux3] Deferred namespace operations, Defer rename, Daniel Phillips, (Sun Dec 14, 5:03 am)
Re: [Tux3] Deferred namespace operations, Defer rename, Daniel Phillips, (Sun Dec 14, 3:50 pm)
Re: [Tux3] Deferred namespace operations, Defer rename, Daniel Phillips, (Sun Dec 14, 7:35 pm)
Re: [Tux3] Deferred namespace operations, Defer rename, Maciej Żenczykowski, (Mon Dec 15, 4:26 am)
Re: [Tux3] Deferred namespace operations, Defer rename, Daniel Phillips, (Mon Dec 15, 11:35 am)
Re: [Tux3] Deferred namespace operations, Defer rename, Maciej Żenczykowski, (Mon Dec 15, 12:31 pm)
Re: [Tux3] Deferred namespace operations, Defer rename, Thomas Bellman, (Tue Dec 16, 2:01 am)