X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=isamb%2Fisamb.c;h=15a825e8e93205170b15768968b1241cacc1c643;hp=c8870320681a41e4a36a9f82e7a0d4ae6fdb8231;hb=289af445bf7c8042b46200f9f2af18049ae049fb;hpb=7149e5607a0d473d958ed1758728cc343b56d681 diff --git a/isamb/isamb.c b/isamb/isamb.c index c887032..15a825e 100644 --- a/isamb/isamb.c +++ b/isamb/isamb.c @@ -1,54 +1,89 @@ -#if 0 + +#include #include -ISAMB isamb_open (const char *name, ISAMC_M method) +struct ISAMB_s { + BFiles bfs; + ISAMC_M method; +}; + +typedef unsigned char *Bpage; + +ISAMB isamb_open (BFiles bfs, const char *name, ISAMC_M method) { ISAMB isamb = xmalloc (sizeof(*isamb)); + + isamb->bfs = bfs; + isamb->method = (ISAMC_M) xmalloc (sizeof(*method)); + memcpy (isamb->method, method, sizeof(*method)); return isamb; } -int isamb_insert (ISAMB is, ISAMB_pos *pos, const void *data) +void isamb_close (ISAMB isamb) { - void *decodeClientData; + xfree (isamb->method); + xfree (isamb); +} - void *page; - if (*pos == 0) - { - *pos = isamb_alloc_block (is, isamb->block_size[0], &page); - isamb_page_set_leaf (page); - isamb_page_set_no (page, 0); - } - else /* find leaf ... */ +#if 0 +/* read page at pos */ +void isamb_get_block (ISAMB is, ISAMB_pos pos, Bpage *page) +{ +} + +/* alloc page */ +ISAMB_pos isamb_alloc_block (ISAMB is, int block_size, Bpage *page) +{ +} + +#define isamb_page_set_leaf (p) 0[p] = 1 +#define isamb_page_set_noleaf (p) 0[p] = 0 +#define isamb_page_datalist (4+p) + +static void isamb_page_set_no(Bpage page, int no) +{ + page[1] = no & 255; + page[2] = (no >> 8) & 255; + page[3] = (no >> 16) & 255; +} + +static int isamb_page_get_no(Bpage page) +{ + return page[1] + 256*page[2] + 65536*page[3]; +} + +void isamb_insert_sub(ISAMB is, ISAMB_pos *pos, const void *data) +{ + const char *src; + char dst[200]; + int no, i; + + isamb_get_block (is, *pos, &page); + if (!isamb_page_isleaf (page)) { - const char *src; - char dst[200]; - int no, i; - while (1) + ISAMB_pos subptr; + src = isamb_page_datalist (page); + no = isamb_page_get_no (page); + decodeClientData = (*is->method->code_start)(ISAMC_DECODE); + + isamb_read_subptr (&subptr, &src); + for (i = 0; imethod->code_item)(ISAMC_DECODE, decodeClientData, + dst, &src); + if ((*is->method->compare_item)(data, dst) < 0) break; - src = isamb_page_datalist (page); - no = isamb_page_get_no (page); - decodeClientData = (*is->method->code_start)(ISAMC_DECODE); - - isamb_read_subptr (&subptr, &src); - for (i = 0; imethod->code_item)(ISAMC_DECODE, decodeClientData, - dst, &src); - if ((*is->method->compare_item)(data, dst) < 0) - break; - - isamb_read_subptr (&subptr, src); - } - *pos = subptr; - (*is->method->code_stop)(ISAMC_DECODE, decodeClientData); + + isamb_read_subptr (&subptr, src); } + isamb_insert_sub (is, subptr, data); + *pos = subptr; + (*is->method->code_stop)(ISAMC_DECODE, decodeClientData); + } + else + { src = isamb_page_datalist (page); no = isamb_page_get_no (page); decodeClientData = (*is->method->code_start)(ISAMC_DECODE); @@ -86,4 +121,22 @@ int isamb_insert (ISAMB is, ISAMB_pos *pos, const void *data) } } } +/* insert data(input) in table is(input) at pos(input/output) */ +int isamb_insert (ISAMB is, ISAMB_pos *pos, const void *data) +{ + void *decodeClientData; + + Bpage page; + if (*pos == 0) + { + *pos = isamb_alloc_block (is, 1024, &page); + isamb_page_set_leaf (page); + isamb_page_set_no (page, 0); + } + else /* find leaf ... */ + { + isamb_insert_sub (is, pos, const void *data); + + } +} #endif