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