src/lib/bbiWrite.c 1.12
1.12 2010/01/30 03:26:32 kent
Fixing it so that while you have to be sorted within a chromosome, the chromosomes themselves need not be sorted.
Index: src/lib/bbiWrite.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/bbiWrite.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -b -B -U 4 -r1.11 -r1.12
--- src/lib/bbiWrite.c 30 Jan 2010 01:03:33 -0000 1.11
+++ src/lib/bbiWrite.c 30 Jan 2010 03:26:32 -0000 1.12
@@ -29,8 +29,18 @@
writeOne(f, sum->sumData);
writeOne(f, sum->sumSquares);
}
+static int bbiChromInfoCmp(const void *va, const void *vb)
+/* Sort bbiChromInfo. Unlike most of our sorts this is single rather
+ * than double indirect. */
+{
+const struct bbiChromInfo *a = (const struct bbiChromInfo *)va;
+const struct bbiChromInfo *b = (const struct bbiChromInfo *)vb;
+return strcmp(a->name, b->name);
+}
+
+
void bbiWriteChromInfo(struct bbiChromUsage *usageList, int blockSize, FILE *f)
/* Write out information on chromosomes to file. */
{
int chromCount = slCount(usageList);
@@ -51,8 +61,11 @@
chromInfoArray[i].id = usage->id;
chromInfoArray[i].size = usage->size;
}
+/* Sort so the b-Tree actually works. */
+qsort(chromInfoArray, chromCount, sizeof(chromInfoArray[0]), bbiChromInfoCmp);
+
/* Write chromosome bPlusTree */
int chromBlockSize = min(blockSize, chromCount);
bptFileBulkIndexToOpenFile(chromInfoArray, sizeof(chromInfoArray[0]), chromCount, chromBlockSize,
bbiChromInfoKey, maxChromNameSize, bbiChromInfoVal,