2 #include <yaz/xmalloc.h>
10 typedef unsigned char *Bpage;
12 ISAMB isamb_open (BFiles bfs, const char *name, ISAMC_M method)
14 ISAMB isamb = xmalloc (sizeof(*isamb));
17 isamb->method = (ISAMC_M) xmalloc (sizeof(*method));
18 memcpy (isamb->method, method, sizeof(*method));
22 void isamb_close (ISAMB isamb)
24 xfree (isamb->method);
29 /* read page at pos */
30 void isamb_get_block (ISAMB is, ISAMB_pos pos, Bpage *page)
35 ISAMB_pos isamb_alloc_block (ISAMB is, int block_size, Bpage *page)
39 #define isamb_page_set_leaf (p) 0[p] = 1
40 #define isamb_page_set_noleaf (p) 0[p] = 0
41 #define isamb_page_datalist (4+p)
43 static void isamb_page_set_no(Bpage page, int no)
46 page[2] = (no >> 8) & 255;
47 page[3] = (no >> 16) & 255;
50 static int isamb_page_get_no(Bpage page)
52 return page[1] + 256*page[2] + 65536*page[3];
55 void isamb_insert_sub(ISAMB is, ISAMB_pos *pos, const void *data)
61 isamb_get_block (is, *pos, &page);
62 if (!isamb_page_isleaf (page))
65 src = isamb_page_datalist (page);
66 no = isamb_page_get_no (page);
67 decodeClientData = (*is->method->code_start)(ISAMC_DECODE);
69 isamb_read_subptr (&subptr, &src);
70 for (i = 0; i<no; i++)
72 const char *src0 = src;
74 (*is->method->code_item)(ISAMC_DECODE, decodeClientData,
76 if ((*is->method->compare_item)(data, dst) < 0)
79 isamb_read_subptr (&subptr, src);
81 isamb_insert_sub (is, subptr, data);
83 (*is->method->code_stop)(ISAMC_DECODE, decodeClientData);
87 src = isamb_page_datalist (page);
88 no = isamb_page_get_no (page);
89 decodeClientData = (*is->method->code_start)(ISAMC_DECODE);
91 for (i = 0; i<no; i++)
94 (*is->method->code_item)(ISAMC_DECODE, decodeClientData,
96 diff = (*is->method->compare_item)(data, dst);
103 src = isamb_page_datalist (page);
104 page2 = isamb_page_dup (is, page);
105 dst2 = isamb_page_datalist (page2);
107 for (j = 0; j <= no; j++)
110 (*is->method->code_item)(ISAMC_ENCODE, encodeClientData,
115 (*is->method->code_item)(ISAMC_DECODE, decodeClientData,
117 (*is->method->code_item)(ISAMC_ENCODE, encodeClientData,
124 /* insert data(input) in table is(input) at pos(input/output) */
125 int isamb_insert (ISAMB is, ISAMB_pos *pos, const void *data)
127 void *decodeClientData;
132 *pos = isamb_alloc_block (is, 1024, &page);
133 isamb_page_set_leaf (page);
134 isamb_page_set_no (page, 0);
136 else /* find leaf ... */
138 isamb_insert_sub (is, pos, const void *data);