]> mj.ucw.cz Git - libucw.git/blob - lib/db_internal.h
Added merger.
[libucw.git] / lib / db_internal.h
1 /*
2  *      Sherlock Library -- Fast Database Management Routines -- Internal Declarations
3  *
4  *      (c) 1999 Martin Mares <mj@ucw.cz>
5  */
6
7 #define SDBM_NUM_FREE_PAGE_POOLS 32
8
9 struct sdbm_root {
10   u32 magic;
11   u32 version;
12   u32 page_order;                       /* Binary logarithm of page size */
13   s32 key_size;                         /* Key/val size, -1=variable */
14   s32 val_size;
15   u32 dir_start;                        /* First page of the page directory */
16   u32 dir_order;                        /* Binary logarithm of directory size */
17   /*
18    *  As we know the only thing which can be freed is the page directory
19    *  and it can grow only a limited number of times, we can use a very
20    *  simple-minded representation of the free page pool. We also assume
21    *  these entries are sorted by start position.
22    */
23   struct {
24     u32 first;
25     u32 count;
26   } free_pool[SDBM_NUM_FREE_PAGE_POOLS];
27 };
28
29 struct sdbm_bucket {
30   u32 used;                             /* Bytes used in this bucket */
31   byte data[0];
32 };
33
34 struct sdbm {
35   struct page_cache *cache;
36   int fd;
37   struct sdbm_root *root;
38   struct page *root_page;
39   int key_size;                         /* Cached values from root page */
40   int val_size;
41   uns page_order;
42   uns page_size;
43   uns page_mask;                        /* page_size - 1 */
44   uns dir_size;                         /* Page directory size in entries */
45   uns dir_shift;                        /* Number of significant bits of hash function */
46   uns file_size;
47   uns flags;
48   uns find_pos;                         /* Current pointer for sdbm_find_next() */
49   uns find_free_list;                   /* First free list entry not skipped by sdbm_find_next() */
50 };
51
52 #define SDBM_MAGIC 0x5344424d
53 #define SDBM_VERSION 1
54
55 #define GET32(p,o) *((u32 *)((p)+(o)))