Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-partition-table.h
1 /*
2  * Copyright (C) 2001 Ximian Inc.
3  *
4  * Authors: Michael Zucchi <notzed@ximian.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef _CAMEL_PARTITION_TABLE_H
22 #define _CAMEL_PARTITION_TABLE_H
23
24 #include <camel/camel-object.h>
25 #include <glib.h>
26 #include <libedataserver/e-msgport.h>
27
28 #include "camel-block-file.h"
29
30 G_BEGIN_DECLS
31
32 /* ********************************************************************** */
33
34 /* CamelPartitionTable - index of key to keyid */
35
36 typedef guint32 camel_hash_t;   /* a hashed key */
37
38 typedef struct _CamelPartitionKey CamelPartitionKey;
39 typedef struct _CamelPartitionKeyBlock CamelPartitionKeyBlock;
40 typedef struct _CamelPartitionMap CamelPartitionMap;
41 typedef struct _CamelPartitionMapBlock CamelPartitionMapBlock;
42
43 typedef struct _CamelPartitionTable CamelPartitionTable;
44 typedef struct _CamelPartitionTableClass CamelPartitionTableClass;
45
46 struct _CamelPartitionKey {
47         camel_hash_t hashid;
48         camel_key_t keyid;
49 };
50
51 struct _CamelPartitionKeyBlock {
52         guint32 used;
53         struct _CamelPartitionKey keys[(CAMEL_BLOCK_SIZE-4)/sizeof(struct _CamelPartitionKey)];
54 };
55
56 struct _CamelPartitionMap {
57         camel_hash_t hashid;
58         camel_block_t blockid;
59 };
60
61 struct _CamelPartitionMapBlock {
62         camel_block_t next;
63         guint32 used;
64         struct _CamelPartitionMap partition[(CAMEL_BLOCK_SIZE-8)/sizeof(struct _CamelPartitionMap)];
65 };
66
67 struct _CamelPartitionTable {
68         CamelObject parent;
69
70         struct _CamelPartitionTablePrivate *priv;
71
72         CamelBlockFile *blocks;
73         camel_block_t rootid;
74
75         int (*is_key)(CamelPartitionTable *cpi, const char *key, camel_key_t keyid, void *data);
76         void *is_key_data;
77
78         /* we keep a list of partition blocks active at all times */
79         EDList partition;
80 };
81
82 struct _CamelPartitionTableClass {
83         CamelObjectClass parent;
84 };
85
86 CamelType camel_partition_table_get_type(void);
87
88 CamelPartitionTable *camel_partition_table_new(struct _CamelBlockFile *bs, camel_block_t root);
89 int camel_partition_table_sync(CamelPartitionTable *cpi);
90 int camel_partition_table_add(CamelPartitionTable *cpi, const char *key, camel_key_t keyid);
91 camel_key_t camel_partition_table_lookup(CamelPartitionTable *cpi, const char *key);
92 void camel_partition_table_remove(CamelPartitionTable *cpi, const char *key);
93
94 /* ********************************************************************** */
95
96 /* CamelKeyTable - index of keyid to key and flag and data mapping */
97
98 typedef struct _CamelKeyBlock CamelKeyBlock;
99 typedef struct _CamelKeyRootBlock CamelKeyRootBlock;
100
101 typedef struct _CamelKeyTable CamelKeyTable;
102 typedef struct _CamelKeyTableClass CamelKeyTableClass;
103
104 struct _CamelKeyRootBlock {
105         camel_block_t first;
106         camel_block_t last;
107         camel_key_t free;       /* free list */
108 };
109
110 struct _CamelKeyKey {
111         camel_block_t data;
112         unsigned int offset:10;
113         unsigned int flags:22;
114 };
115
116 struct _CamelKeyBlock {
117         camel_block_t next;
118         guint32 used;
119         union {
120                 struct _CamelKeyKey keys[(CAMEL_BLOCK_SIZE-8)/sizeof(struct _CamelKeyKey)];
121                 char keydata[CAMEL_BLOCK_SIZE-8];
122         } u;
123 };
124
125 #define CAMEL_KEY_TABLE_MAX_KEY (128) /* max size of any key */
126
127 struct _CamelKeyTable {
128         CamelObject parent;
129
130         struct _CamelKeyTablePrivate *priv;
131
132         CamelBlockFile *blocks;
133
134         camel_block_t rootid;
135
136         CamelKeyRootBlock *root;
137         CamelBlock *root_block;
138 };
139
140 struct _CamelKeyTableClass {
141         CamelObjectClass parent;
142 };
143
144 CamelType camel_key_table_get_type(void);
145
146 CamelKeyTable * camel_key_table_new(CamelBlockFile *bs, camel_block_t root);
147 int camel_key_table_sync(CamelKeyTable *ki);
148 camel_key_t camel_key_table_add(CamelKeyTable *ki, const char *key, camel_block_t data, unsigned int flags);
149 void camel_key_table_set_data(CamelKeyTable *ki, camel_key_t keyid, camel_block_t data);
150 void camel_key_table_set_flags(CamelKeyTable *ki, camel_key_t keyid, unsigned int flags, unsigned int set);
151 camel_block_t camel_key_table_lookup(CamelKeyTable *ki, camel_key_t keyid, char **key, unsigned int *flags);
152 camel_key_t camel_key_table_next(CamelKeyTable *ki, camel_key_t next, char **keyp, unsigned int *flagsp, camel_block_t *datap);
153
154 G_END_DECLS
155
156 #endif /* ! _CAMEL_PARTITION_TABLE_H */