Wrap text
Report abuse
diff -r aafbec810c36 user/test/dleaf.c
--- a/user/test/dleaf.c Tue Sep 02 12:09:21 2008 -0700
+++ b/user/test/dleaf.c Tue Sep 02 20:18:32 2008 -0700
@@ -165,6 +165,44 @@
return NULL;
}
+int dleaf_dump2(BTREE, struct dleaf *leaf)
+{
+ struct group *gdict = (void *)leaf + btree->sb->blocksize;
+ struct entry *edict = (void *)(gdict - leaf->groups);
+ printf("%i entry groups:\n", leaf->groups);
+ for (int grp = -1, offset = 0, grpoffset = 0, ent; grp >= -leaf->groups; grp--)
+ {
+ printf(" %i/%i:", -grp - 1, gdict[grp].count);
+ for (ent = -1; ent >= -gdict[grp].count; ent--)
+ {
+ int prevlimit = (ent == -1) ? 0 : edict[offset + ent + 1].limit;
+ printf(" %Lx ->", ((L)gdict[grp].loghi) << 24 | edict[offset + ent].loglo);
+ int size = edict[offset + ent].limit - prevlimit;
+ if (size < 0)
+ printf(" ");
+ else for (int i = 0; i < size; i++)
+ printf(" %Lx", (L)leaf->table[grpoffset + prevlimit + i].block);
+ printf(";");
+ }
+ if (gdict[grp].count > 0)
+ grpoffset += edict[offset - gdict[grp].count].limit;
+ offset -= gdict[grp].count;
+ printf("\n");
+ }
+ return 1;
+}
+
+int dleaf_isinorder(BTREE, struct dleaf *leaf)
+{
+ struct group *gdict = (void *)leaf + btree->sb->blocksize;
+ struct entry *edict = (void *)(gdict - leaf->groups);
+ for (int grp = -1; grp >= -leaf->groups; grp--)
+ for (int ent = -1; ent >= -gdict[grp].count; ent--)
+ if (ent < -1 && edict[ent].limit < edict[ent + 1].limit)
+ return 0;
+ return 1;
+}
+
int dleaf_check(BTREE, struct dleaf *leaf)
{
struct group *groups = (void *)leaf + btree->sb->blocksize, *grbase = --groups - leaf->groups;
@@ -184,6 +222,9 @@
goto eek;
why = "used count wrong";
if (leaf->used != (void *)(entries - encount) - (void *)leaf)
+ goto eek;
+ why = "dleaf entries out of order";
+ if (!dleaf_isinorder(btree, leaf))
goto eek;
return 0;
eek:
@@ -470,6 +511,7 @@
dleaf_merge(btree, leaf, dest);
dleaf_check(btree, leaf);
dleaf_dump(btree, leaf);
+ dleaf_dump2(btree, leaf);
dleaf_destroy(btree, leaf);
dleaf_destroy(btree, dest);
return 0;
diff -r aafbec810c36 user/test/ileaf.c
--- a/user/test/ileaf.c Tue Sep 02 12:09:21 2008 -0700
+++ b/user/test/ileaf.c Tue Sep 02 20:18:32 2008 -0700
@@ -124,7 +124,7 @@
return attrs;
}
-int isinorder(BTREE, struct ileaf *leaf)
+int ileaf_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)
@@ -140,7 +140,7 @@
if (leaf->magic != 0x90de);
goto eek;
why = "dict out of order";
- if (!isinorder(btree, leaf))
+ if (!ileaf_isinorder(btree, leaf))
goto eek;
return 0;
eek: