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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <tux3@...>
Cc: Conrad Meyer <konrad@...>
Date: Tuesday, September 2, 2008 - 5: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:
[Tux3] Deferred namespace operations, Defer rename, Daniel Phillips, (Sun Dec 14, 8:03 am)
Re: [Tux3] Deferred namespace operations, Defer rename, Maciej Żenczykowski, (Mon Dec 15, 7:26 am)
Re: [Tux3] Deferred namespace operations, Defer rename, Daniel Phillips, (Mon Dec 15, 2:35 pm)
Re: [Tux3] Deferred namespace operations, Defer rename, Maciej Żenczykowski, (Mon Dec 15, 3:31 pm)
Re: [Tux3] Deferred namespace operations, Defer rename, Thomas Bellman, (Tue Dec 16, 5:01 am)
Re: [Tux3] Deferred namespace operations, Defer rename, Daniel Phillips, (Sun Dec 14, 6:50 pm)
Re: [Tux3] Deferred namespace operations, Defer rename, Daniel Phillips, (Sun Dec 14, 10:35 pm)
Re: [Tux3] [PATCH] Make sure ileaf offsets are in non-descen..., Daniel Phillips, (Tue Sep 2, 5:27 am)