2 * Copyright (C) 2001 Ximian Inc.
4 * Authors: Michael Zucchi <notzed@ximian.com>
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.
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.
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.
21 #ifndef _CAMEL_PARTITION_TABLE_H
22 #define _CAMEL_PARTITION_TABLE_H
24 #include <camel/camel-object.h>
26 #include <libedataserver/e-msgport.h>
28 #include "camel-block-file.h"
32 /* ********************************************************************** */
34 /* CamelPartitionTable - index of key to keyid */
36 typedef guint32 camel_hash_t; /* a hashed key */
38 typedef struct _CamelPartitionKey CamelPartitionKey;
39 typedef struct _CamelPartitionKeyBlock CamelPartitionKeyBlock;
40 typedef struct _CamelPartitionMap CamelPartitionMap;
41 typedef struct _CamelPartitionMapBlock CamelPartitionMapBlock;
43 typedef struct _CamelPartitionTable CamelPartitionTable;
44 typedef struct _CamelPartitionTableClass CamelPartitionTableClass;
46 struct _CamelPartitionKey {
51 struct _CamelPartitionKeyBlock {
53 struct _CamelPartitionKey keys[(CAMEL_BLOCK_SIZE-4)/sizeof(struct _CamelPartitionKey)];
56 struct _CamelPartitionMap {
58 camel_block_t blockid;
61 struct _CamelPartitionMapBlock {
64 struct _CamelPartitionMap partition[(CAMEL_BLOCK_SIZE-8)/sizeof(struct _CamelPartitionMap)];
67 struct _CamelPartitionTable {
70 struct _CamelPartitionTablePrivate *priv;
72 CamelBlockFile *blocks;
75 int (*is_key)(CamelPartitionTable *cpi, const char *key, camel_key_t keyid, void *data);
78 /* we keep a list of partition blocks active at all times */
82 struct _CamelPartitionTableClass {
83 CamelObjectClass parent;
86 CamelType camel_partition_table_get_type(void);
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);
94 /* ********************************************************************** */
96 /* CamelKeyTable - index of keyid to key and flag and data mapping */
98 typedef struct _CamelKeyBlock CamelKeyBlock;
99 typedef struct _CamelKeyRootBlock CamelKeyRootBlock;
101 typedef struct _CamelKeyTable CamelKeyTable;
102 typedef struct _CamelKeyTableClass CamelKeyTableClass;
104 struct _CamelKeyRootBlock {
107 camel_key_t free; /* free list */
110 struct _CamelKeyKey {
112 unsigned int offset:10;
113 unsigned int flags:22;
116 struct _CamelKeyBlock {
120 struct _CamelKeyKey keys[(CAMEL_BLOCK_SIZE-8)/sizeof(struct _CamelKeyKey)];
121 char keydata[CAMEL_BLOCK_SIZE-8];
125 #define CAMEL_KEY_TABLE_MAX_KEY (128) /* max size of any key */
127 struct _CamelKeyTable {
130 struct _CamelKeyTablePrivate *priv;
132 CamelBlockFile *blocks;
134 camel_block_t rootid;
136 CamelKeyRootBlock *root;
137 CamelBlock *root_block;
140 struct _CamelKeyTableClass {
141 CamelObjectClass parent;
144 CamelType camel_key_table_get_type(void);
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);
156 #endif /* ! _CAMEL_PARTITION_TABLE_H */