48
48
49
49
*/
50
50
51
+ #define UCDB_VERSION_MAJOR 0
52
+ #define UCDB_VERSION_MINOR 5
53
+ #define UCDB_VERSION_PATCH 3
54
+
51
55
#ifdef TRACE_CDB
52
56
#ifndef TracePrinter
53
57
#define TracePrinter Serial
@@ -144,6 +148,7 @@ class uCDB
144
148
unsigned long dataEndPos; // /< Data end position
145
149
unsigned long slotsNum; // /< Total slots number in CDB.
146
150
151
+ unsigned int hashTabID_; // /< Last accessed hash table
147
152
// / @name Hash table descriptor (HEADER section)
148
153
// / @{
149
154
unsigned long hashTabStartPos; // /< Hash table position
@@ -201,6 +206,7 @@ cdbResult uCDB<TFileSystem, TFile>::open(const char *fileName, unsigned long (*u
201
206
// Close previously opened CDB file
202
207
// State - CDB_CLOSED
203
208
close ();
209
+ hashTabID_ = -1 ;
204
210
205
211
if (!fs_.exists (fileName)) {
206
212
return CDB_NOT_FOUND;
@@ -263,6 +269,7 @@ cdbResult uCDB<TFileSystem, TFile>::open(const char *fileName, unsigned long (*u
263
269
template <class TFileSystem , class TFile >
264
270
cdbResult uCDB<TFileSystem, TFile>::findKey(const void *key, unsigned long keyLen) {
265
271
byte buff[CDB_DESCRIPTOR_SIZE];
272
+ unsigned int hashTabID;
266
273
267
274
zero ();
268
275
// Check CDB state
@@ -274,17 +281,21 @@ cdbResult uCDB<TFileSystem, TFile>::findKey(const void *key, unsigned long keyLe
274
281
;
275
282
}
276
283
277
- keyHash = hashFunc (key, keyLen);
278
284
key_ = static_cast <const byte *>(key);
279
285
keyLen_ = keyLen;
286
+ keyHash = hashFunc (key, keyLen);
287
+ hashTabID = keyHash & 255 ;
288
+
289
+ if (hashTabID != hashTabID_) {
290
+ if (!readDescriptor<TFile>(cdb, buff, hashTabID << 3 )) {
291
+ RETURN (state = FILE_ERROR, FILE_ERROR);
292
+ }
280
293
281
- if (!readDescriptor<TFile>(cdb, buff, (keyHash & 255 ) << 3 )) {
282
- RETURN (state = FILE_ERROR, FILE_ERROR);
294
+ hashTabStartPos = unpack (buff);
295
+ hashTabSlotsNum = unpack (buff + 4 );
296
+ hashTabEndPos = hashTabStartPos + hashTabSlotsNum * CDB_DESCRIPTOR_SIZE;
297
+ hashTabID_ = hashTabID;
283
298
}
284
-
285
- hashTabStartPos = unpack (buff);
286
- hashTabSlotsNum = unpack (buff + 4 );
287
- hashTabEndPos = hashTabStartPos + hashTabSlotsNum * CDB_DESCRIPTOR_SIZE;
288
299
slotsToScan = hashTabSlotsNum;
289
300
nextSlotPos = hashTabStartPos + ((keyHash >> 8 ) % hashTabSlotsNum) * 8 ;
290
301
0 commit comments