158d5534e58e85e42aa39119a0803e2277bdb0ae
[idzebra-moved-to-github.git] / include / isamd.h
1 /*
2  * Copyright (c) 1995-2002, Index Data.
3  * See the file LICENSE for details.
4  *
5  * Isam-D, Heikki's second Isam. 
6  * The first block of an isam entry contains deltas to the
7  * (possibly long) sequence of keys. Thus small changes consist
8  * only of adding deltas to a small list, and affect only one 
9  * block. Occasionally the block gets full, and needs to be 
10  * merged with the rest.
11  * 
12  * Heikki Levanto
13  *
14  * Detailed log at the end of the file
15  *
16  */
17
18 #ifndef ISAMD_H
19 #define ISAMD_H
20
21 #include <bfile.h>
22
23 YAZ_BEGIN_CDECL
24
25 typedef struct ISAMD_s *ISAMD;
26 typedef int ISAMD_P;
27 typedef struct ISAMD_PP_s *ISAMD_PP;
28
29 typedef struct ISAMD_filecat_s {  /* filecategories, mostly block sizes */
30     int bsize;         /* block size */
31     int mblocks;       /* maximum keys before switching to larger sizes */
32 } *ISAMD_filecat;
33
34 typedef struct ISAMD_M_s {
35     ISAMD_filecat filecat;
36
37     int (*compare_item)(const void *a, const void *b);
38
39 #define ISAMD_DECODE 0
40 #define ISAMD_ENCODE 1
41     void *(*code_start)(int mode);
42     void (*code_stop)(int mode, void *p);
43     void (*code_item)(int mode, void *p, char **dst, char **src);
44     void (*code_reset)(void *p);
45
46     int max_blocks_mem;
47     int debug;
48 } *ISAMD_M;
49
50 typedef struct ISAMD_I_s {  /* encapsulation of input data */
51     int (*read_item)(void *clientData, char **dst, int *insertMode);
52     void *clientData;
53 } *ISAMD_I;
54
55 ISAMD_M isamd_getmethod (ISAMD_M me);
56
57 ISAMD isamd_open (BFiles bfs, const char *name, int writeflag, ISAMD_M method);
58 int isamd_close (ISAMD is);
59 /*ISAMD_P isamd_append (ISAMD is, ISAMD_P pos, ISAMD_I data);*/
60 int isamd_append (ISAMD is, char *dictentry, int dictlen, ISAMD_I data);
61
62   
63   
64 /* Shortcut: If the isam is relatively short, we store the */
65 /* whole thing in the dictionary, and allocate no blocks at all! */
66 #define ISAMD_MAX_DICT_LEN 16
67
68 /*ISAMD_PP isamd_pp_open (ISAMD is, const char *dictbuf);*/
69 ISAMD_PP isamd_pp_open (ISAMD is, const char *dictbuf, int dictlen);
70 ISAMD_PP isamd_pp_create (ISAMD is, int cat);
71
72 void isamd_pp_close (ISAMD_PP pp);
73 int isamd_read_item (ISAMD_PP pp, char **dst);
74 int isamd_read_main_item (ISAMD_PP pp, char **dst);
75 int isamd_pp_read (ISAMD_PP pp, void *buf);
76 int isamd_pp_num (ISAMD_PP pp);
77
78 int isamd_block_used (ISAMD is, int type);
79 int isamd_block_size (ISAMD is, int type);
80
81
82 #define isamd_type(x) ((x) & 7)
83 #define isamd_block(x) ((x) >> 3)
84 #define isamd_addr(blk,typ) (((blk)<<3)+(typ))
85
86 void isamd_buildfirstblock(ISAMD_PP pp);
87 void isamd_buildlaterblock(ISAMD_PP pp);
88
89 YAZ_END_CDECL
90
91 #endif  /* ISAMD_H */
92
93
94 /*
95  * $Log: isamd.h,v $
96  * Revision 1.3  1999/08/18 08:33:41  heikki
97  * Fixes
98  *
99  * Revision 1.2  1999/07/14 13:21:34  heikki
100  * Added isam-d files. Compiles (almost) clean. Doesn't work at all
101  *
102  * Revision 1.1  1999/07/14 12:34:43  heikki
103  * Copied from isamh, starting to change things...
104  *
105  *
106  */