diff audioDB.cpp @ 140:ddd83d773d6c

Smaller databases Adjust the sizes of the various tables (file, track, times, l2norm) linearly with the overall size of the database. Now it makes sense to allow 50Mb databases, as the various fixed-size tables shrink, rather than being fixed to somewhere over that size...
author mas01cr
date Mon, 29 Oct 2007 11:47:42 +0000
parents a5d5a55a412d
children c74048e9b569 5fa52830e532
line wrap: on
line diff
--- a/audioDB.cpp	Mon Oct 29 11:45:50 2007 +0000
+++ b/audioDB.cpp	Mon Oct 29 11:47:42 2007 +0000
@@ -153,7 +153,7 @@
   }
 
   if(args_info.size_given) {
-    if (args_info.size_arg < 250 || args_info.size_arg > 4000) {
+    if (args_info.size_arg < 50 || args_info.size_arg > 4000) {
       error("Size out of range", "");
     }
     size = args_info.size_arg * 1000000;
@@ -398,6 +398,8 @@
   dbH = new dbTableHeaderT();
   assert(dbH);
 
+  unsigned int maxfiles = (unsigned int) rint((double) O2_MAXFILES * (double) size / (double) O2_DEFAULTDBSIZE);
+
   // Initialize header
   dbH->magic = O2_MAGIC;
   dbH->version = O2_FORMAT_VERSION;
@@ -406,10 +408,10 @@
   dbH->flags = 0;
   dbH->length = 0;
   dbH->fileTableOffset = ALIGN_UP(O2_HEADERSIZE, 8);
-  dbH->trackTableOffset = ALIGN_UP(dbH->fileTableOffset + O2_FILETABLESIZE*O2_MAXFILES, 8);
-  dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*O2_MAXFILES, 8);
-  dbH->l2normTableOffset = ALIGN_DOWN(size - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
-  dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - O2_MAXFILES*O2_MEANNUMVECTORS*sizeof(double), 8);
+  dbH->trackTableOffset = ALIGN_UP(dbH->fileTableOffset + O2_FILETABLESIZE*maxfiles, 8);
+  dbH->dataOffset = ALIGN_UP(dbH->trackTableOffset + O2_TRACKTABLESIZE*maxfiles, 8);
+  dbH->l2normTableOffset = ALIGN_DOWN(size - maxfiles*O2_MEANNUMVECTORS*sizeof(double), 8);
+  dbH->timesTableOffset = ALIGN_DOWN(dbH->l2normTableOffset - maxfiles*O2_MEANNUMVECTORS*sizeof(double), 8);
   dbH->dbSize = size;
 
   memcpy (db, dbH, O2_HEADERSIZE);