comparison audioDB.h @ 108:bc141fd1dc41

New on-disk format! * new magic number: "o2db" rather than "O2DB". Check for the old one and give a helpful error message. (We could in principle handle the old databases transparently, but since only MC has actually used them and he has indicated that this is not desperately necessary...) * add fields to header: a file format version (currently 0; we have 2^32-1 revisions to make before we have to worry...) and fields for the offsets of the various tables. This is hopefully a little bit more futureproof: we can move the default locations of the tables around, and even adding new optional tables can be done easily in a fairly transparent manner (if the relevant header field is 0, don't use that feature). * align regions to the appropriate 32-word boundary. This gives us some space to breathe for in the header (admittedly only 15 words on 64-bit architectures...)
author mas01cr
date Fri, 05 Oct 2007 14:21:43 +0000
parents 10feb98abebf
children 43722a0ba717
comparison
equal deleted inserted replaced
106:a0e422e3c553 108:bc141fd1dc41
42 #define COM_FEATURES "--features" 42 #define COM_FEATURES "--features"
43 #define COM_QUERYKEY "--key" 43 #define COM_QUERYKEY "--key"
44 #define COM_KEYLIST "--keyList" 44 #define COM_KEYLIST "--keyList"
45 #define COM_TIMES "--times" 45 #define COM_TIMES "--times"
46 46
47 #define O2_MAGIC 1111765583 // 'B'<<24|'D'<<16|'2'<<8|'O' reads O2DB in little endian order 47 #define O2_OLD_MAGIC ('O'|'2'<<8|'D'<<16|'B'<<24)
48 #define O2_MAGIC ('o'|'2'<<8|'d'<<16|'b'<<24)
49 #define O2_FORMAT_VERSION (0U)
48 50
49 #define O2_DEFAULT_POINTNN (10U) 51 #define O2_DEFAULT_POINTNN (10U)
50 #define O2_DEFAULT_TRACKNN (10U) 52 #define O2_DEFAULT_TRACKNN (10U)
51 53
52 #define O2_DEFAULTDBSIZE (2000000000) // 2GB table size 54 #define O2_DEFAULTDBSIZE (2000000000) // 2GB table size
76 #define O2_ERR_KEYNOTFOUND (0xFFFFFF00) 78 #define O2_ERR_KEYNOTFOUND (0xFFFFFF00)
77 79
78 // Macros 80 // Macros
79 #define O2_ACTION(a) (strcmp(command,a)==0) 81 #define O2_ACTION(a) (strcmp(command,a)==0)
80 82
83 #define ALIGN_UP(x,w) ((x) + ((1<<w)-1) & ~((1<<w)-1))
84 #define ALIGN_DOWN(x,w) ((x) & ~((1<<w)-1))
85
81 using namespace std; 86 using namespace std;
82 87
83 // 64 byte header 88 // 64 byte header
84 typedef struct dbTableHeader{ 89 typedef struct dbTableHeader{
85 unsigned magic; 90 unsigned magic;
91 unsigned version;
86 unsigned numFiles; 92 unsigned numFiles;
87 unsigned dim; 93 unsigned dim;
88 unsigned length;
89 unsigned flags; 94 unsigned flags;
95 size_t length;
96 size_t fileTableOffset;
97 size_t trackTableOffset;
98 size_t dataOffset;
99 size_t l2normTableOffset;
100 size_t timesTableOffset;
90 } dbTableHeaderT, *dbTableHeaderPtr; 101 } dbTableHeaderT, *dbTableHeaderPtr;
91 102
92 103
93 class audioDB{ 104 class audioDB{
94 105
109 int infid; 120 int infid;
110 char* db; 121 char* db;
111 char* indata; 122 char* indata;
112 struct stat statbuf; 123 struct stat statbuf;
113 dbTableHeaderPtr dbH; 124 dbTableHeaderPtr dbH;
114 size_t fileTableOffset;
115 size_t trackTableOffset;
116 size_t dataoffset;
117 size_t l2normTableOffset;
118 size_t timesTableOffset;
119 125
120 char *fileTable; 126 char *fileTable;
121 unsigned* trackTable; 127 unsigned* trackTable;
122 double* dataBuf; 128 double* dataBuf;
123 double* inBuf; 129 double* inBuf;